Search in sources :

Example 36 with MetaDataStore

use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.

the class DefaultQueryPlanMergerTest method testSimpleMerge.

@Test
public void testSimpleMerge() {
    Queryable source = mock(Queryable.class);
    // A root source.
    when(source.getSource()).thenReturn(source);
    MetricProjection m1 = mock(MetricProjection.class);
    MetricProjection m2 = mock(MetricProjection.class);
    when(m1.getName()).thenReturn("m1");
    when(m2.getName()).thenReturn("m2");
    DimensionProjection d1 = mock(DimensionProjection.class);
    DimensionProjection d2 = mock(DimensionProjection.class);
    when(d1.getName()).thenReturn("d1");
    when(d2.getName()).thenReturn("d2");
    TimeDimensionProjection t1 = mock(TimeDimensionProjection.class);
    TimeDimensionProjection t2 = mock(TimeDimensionProjection.class);
    when(t1.getName()).thenReturn("t1");
    when(t2.getName()).thenReturn("t2");
    QueryPlan a = QueryPlan.builder().source(source).metricProjection(m1).dimensionProjection(d1).timeDimensionProjection(t1).build();
    QueryPlan b = QueryPlan.builder().source(source).metricProjection(m2).dimensionProjection(d2).timeDimensionProjection(t2).build();
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    DefaultQueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    QueryPlan c = merger.merge(a, b);
    assertEquals(List.of(m2, m1), c.getMetricProjections());
    assertEquals(List.of(d2, d1), c.getDimensionProjections());
    assertEquals(List.of(t2, t1), c.getTimeDimensionProjections());
}
Also used : MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Test(org.junit.jupiter.api.Test)

Example 37 with MetaDataStore

use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.

the class DefaultQueryPlanMergerTest method testCannotMergeMismatchedUnnestedWhere.

@Test
public void testCannotMergeMismatchedUnnestedWhere() {
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    DefaultQueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    QueryPlan a = mock(QueryPlan.class);
    QueryPlan b = mock(QueryPlan.class);
    when(a.canNest(any())).thenReturn(false);
    when(b.canNest(any())).thenReturn(false);
    when(a.nestDepth()).thenReturn(1);
    when(b.nestDepth()).thenReturn(1);
    FilterExpression expression = mock(FilterExpression.class);
    when(a.getWhereFilter()).thenReturn(expression);
    when(b.getWhereFilter()).thenReturn(null);
    assertFalse(merger.canMerge(a, b));
    assertFalse(merger.canMerge(b, a));
}
Also used : MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 38 with MetaDataStore

use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.

the class DefaultQueryPlanMergerTest method testCanMerge.

@Test
public void testCanMerge() {
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    DefaultQueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    QueryPlan a = mock(QueryPlan.class);
    QueryPlan b = mock(QueryPlan.class);
    when(a.canNest(any())).thenReturn(false);
    when(b.canNest(any())).thenReturn(false);
    when(a.nestDepth()).thenReturn(1);
    when(b.nestDepth()).thenReturn(1);
    FilterExpression expression = mock(FilterExpression.class);
    when(a.getWhereFilter()).thenReturn(expression);
    when(b.getWhereFilter()).thenReturn(expression);
    TimeDimensionProjection p1 = mock(TimeDimensionProjection.class);
    Map<String, Argument> args1 = new HashMap<>();
    args1.put("foo", Argument.builder().name("a").value(100).build());
    when(p1.getName()).thenReturn("name");
    when(p1.getArguments()).thenReturn(args1);
    TimeDimensionProjection p2 = mock(TimeDimensionProjection.class);
    Map<String, Argument> args2 = new HashMap<>();
    args2.put("foo", Argument.builder().name("a").value(100).build());
    when(p2.getName()).thenReturn("name");
    when(p2.getArguments()).thenReturn(args2);
    when(a.getTimeDimensionProjections()).thenReturn(List.of(p1));
    when(b.getTimeDimensionProjections()).thenReturn(List.of(p2));
    when(b.getTimeDimensionProjection(eq("name"))).thenReturn(p2);
    when(a.getTimeDimensionProjection(eq("name"))).thenReturn(p1);
    assertTrue(merger.canMerge(a, b));
    assertTrue(merger.canMerge(b, a));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 39 with MetaDataStore

use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.

the class DefaultQueryPlanMergerTest method testCannotMergeMismatchedTimeDimension.

@Test
public void testCannotMergeMismatchedTimeDimension() {
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    DefaultQueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    QueryPlan a = mock(QueryPlan.class);
    QueryPlan b = mock(QueryPlan.class);
    when(a.canNest(any())).thenReturn(false);
    when(b.canNest(any())).thenReturn(false);
    when(a.nestDepth()).thenReturn(1);
    when(b.nestDepth()).thenReturn(1);
    TimeDimensionProjection p1 = mock(TimeDimensionProjection.class);
    Map<String, Argument> args1 = new HashMap<>();
    when(p1.getName()).thenReturn("name");
    when(p1.getArguments()).thenReturn(args1);
    TimeDimensionProjection p2 = mock(TimeDimensionProjection.class);
    Map<String, Argument> args2 = new HashMap<>();
    args2.put("foo", Argument.builder().name("a").value(100).build());
    when(p2.getName()).thenReturn("name");
    when(p2.getArguments()).thenReturn(args2);
    when(a.getTimeDimensionProjections()).thenReturn(List.of(p1));
    when(b.getTimeDimensionProjections()).thenReturn(List.of(p2));
    when(b.getTimeDimensionProjection(eq("name"))).thenReturn(p2);
    when(a.getTimeDimensionProjection(eq("name"))).thenReturn(p1);
    assertFalse(merger.canMerge(a, b));
    assertFalse(merger.canMerge(b, a));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Test(org.junit.jupiter.api.Test)

Example 40 with MetaDataStore

use of com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore in project elide by yahoo.

the class DefaultQueryPlanMergerTest method testCannotMergeNoNesting.

@Test
public void testCannotMergeNoNesting() {
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    DefaultQueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    QueryPlan a = mock(QueryPlan.class);
    QueryPlan b = mock(QueryPlan.class);
    when(a.canNest(any())).thenReturn(false);
    when(b.canNest(any())).thenReturn(true);
    when(a.nestDepth()).thenReturn(1);
    when(b.nestDepth()).thenReturn(2);
    assertFalse(merger.canMerge(a, b));
    assertFalse(merger.canMerge(b, a));
}
Also used : MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Test(org.junit.jupiter.api.Test)

Aggregations

MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)45 Test (org.junit.jupiter.api.Test)28 HashSet (java.util.HashSet)27 SQLQueryEngine (com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine)25 DefaultQueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)24 QueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.QueryPlanMerger)19 Table (com.yahoo.elide.modelconfig.model.Table)17 Arrays (java.util.Arrays)9 Set (java.util.Set)9 Argument (com.yahoo.elide.core.request.Argument)8 List (java.util.List)8 Map (java.util.Map)8 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)7 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)7 Type (com.yahoo.elide.core.type.Type)7 DefaultClassScanner (com.yahoo.elide.core.utils.DefaultClassScanner)7 DefaultQueryValidator (com.yahoo.elide.datastores.aggregation.DefaultQueryValidator)7 ConnectionDetails (com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails)7 Collectors (java.util.stream.Collectors)7 Query (com.yahoo.elide.datastores.aggregation.query.Query)6