Search in sources :

Example 11 with MetaDataStore

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

the class DefaultQueryPlanMergerTest method testCannotMergeMismatchedDimension.

@Test
public void testCannotMergeMismatchedDimension() {
    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);
    DimensionProjection p1 = mock(DimensionProjection.class);
    Map<String, Argument> args1 = new HashMap<>();
    when(p1.getName()).thenReturn("name");
    when(p1.getArguments()).thenReturn(args1);
    DimensionProjection p2 = mock(DimensionProjection.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.getDimensionProjections()).thenReturn(List.of(p1));
    when(b.getDimensionProjections()).thenReturn(List.of(p2));
    when(b.getDimensionProjection(eq("name"))).thenReturn(p2);
    when(a.getDimensionProjection(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 12 with MetaDataStore

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

the class DefaultQueryPlanMergerTest method testCannotMergeMismatchedNestedWhere.

@Test
public void testCannotMergeMismatchedNestedWhere() {
    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");
    when(m1.canNest(any(), any())).thenReturn(true);
    when(m1.nest(any(), any(), anyBoolean())).thenReturn(Pair.of(m1, Set.of(m1)));
    when(m2.canNest(any(), any())).thenReturn(true);
    when(m2.nest(any(), any(), anyBoolean())).thenReturn(Pair.of(m2, Set.of(m2)));
    FilterExpression filterA = mock(FilterExpression.class);
    FilterExpression filterB = mock(FilterExpression.class);
    QueryPlan a = QueryPlan.builder().source(source).whereFilter(filterA).metricProjection(m1).build();
    QueryPlan nested = QueryPlan.builder().source(source).whereFilter(filterB).metricProjection(m2).build();
    QueryPlan b = QueryPlan.builder().source(nested).metricProjection(m2).build();
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    DefaultQueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    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 13 with MetaDataStore

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

the class TableArgumentValidatorTest method testUndefinedTableArgsInTableSql.

@Test
public void testUndefinedTableArgsInTableSql() {
    Table mainTable = mainTableBuilder.sql("SELECT something {{$$table.args.mainArg1}} blah {{$$table.args.mainArg2}} FROM").build();
    Set<Table> tables = new HashSet<>();
    tables.add(mainTable);
    MetaDataStore metaDataStore = new MetaDataStore(DefaultClassScanner.getInstance(), tables, this.namespaceConfigs, true);
    QueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    Exception e = assertThrows(IllegalStateException.class, () -> new SQLQueryEngine(metaDataStore, connectionLookup, optimizers, merger, queryValidator));
    assertEquals("Failed to verify table arguments for table: namespace_MainTable. Argument 'mainArg2' is not defined but found '{{$$table.args.mainArg2}}' in table's sql.", e.getMessage());
}
Also used : SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) QueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.QueryPlanMerger) Table(com.yahoo.elide.modelconfig.model.Table) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 14 with MetaDataStore

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

the class TableArgumentValidatorTest method testRequiredTableArgsForJoinTableInFilterTemplate.

@Test
public void testRequiredTableArgsForJoinTableInFilterTemplate() {
    Table mainTable = Table.builder().name("MainTable").namespace("namespace").filterTemplate("foo>{{filterArg1}}").join(Join.builder().name("join").namespace("namespace").to("JoinTable").definition("start {{$$table.args.filterArg1}} end").build()).build();
    Set<Table> tables = new HashSet<>();
    tables.add(mainTable);
    tables.add(Table.builder().name("JoinTable").namespace("namespace").build());
    assertDoesNotThrow(() -> {
        new MetaDataStore(DefaultClassScanner.getInstance(), tables, this.namespaceConfigs, true);
    });
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 15 with MetaDataStore

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

the class TableArgumentValidatorTest method testDefaultValueIsInValues.

@Test
public void testDefaultValueIsInValues() {
    Table mainTable = mainTableBuilder.argument(Argument.builder().name("testArg").type(Type.INTEGER).values(Sets.newHashSet("1", "2")).defaultValue("5").build()).build();
    Set<Table> tables = new HashSet<>();
    tables.add(mainTable);
    MetaDataStore metaDataStore = new MetaDataStore(DefaultClassScanner.getInstance(), tables, this.namespaceConfigs, true);
    QueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    Exception e = assertThrows(IllegalStateException.class, () -> new SQLQueryEngine(metaDataStore, connectionLookup, optimizers, merger, queryValidator));
    assertEquals("Failed to verify table arguments for table: namespace_MainTable. Default Value: '5' for Argument 'testArg' with Type 'INTEGER' must match one of these values: [1, 2].", e.getMessage());
}
Also used : SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) QueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.QueryPlanMerger) Table(com.yahoo.elide.modelconfig.model.Table) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) HashSet(java.util.HashSet) 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