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));
}
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));
}
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());
}
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);
});
}
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());
}
Aggregations