use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.
the class TableTypeTest method testDimensionTableValues.
@Test
void testDimensionTableValues() throws Exception {
Set<String> values = new HashSet<>(Arrays.asList("DIM1", "DIM2"));
Table testTable = Table.builder().table("table1").name("Table").dimension(Dimension.builder().type(Type.COORDINATE).name("location").values(values).build()).build();
TableType testType = new TableType(testTable);
Field field = testType.getDeclaredField("location");
assertNotNull(field);
ColumnMeta columnMeta = field.getAnnotation(ColumnMeta.class);
assertEquals(values, new HashSet<>(Arrays.asList(columnMeta.values())));
}
use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.
the class TableTypeTest method testJoinField.
@Test
void testJoinField() throws Exception {
Table testTable1 = Table.builder().name("table1").join(Join.builder().definition("{{id }} = {{ table2.id}}").kind(Join.Kind.TOONE).type(Join.Type.INNER).name("join1").to("table2.dim2").build()).build();
Table testTable2 = Table.builder().name("table2").dimension(Dimension.builder().name("dim2").type(Type.BOOLEAN).build()).build();
TableType testType1 = new TableType(testTable1);
TableType testType2 = new TableType(testTable2);
Map<String, com.yahoo.elide.core.type.Type<?>> tables = new HashMap<>();
tables.put("table1", testType1);
tables.put("table2", testType2);
testType1.resolveJoins(tables);
Field field = testType1.getDeclaredField("join1");
assertNotNull(field);
com.yahoo.elide.datastores.aggregation.annotation.Join join = field.getAnnotation(com.yahoo.elide.datastores.aggregation.annotation.Join.class);
assertEquals(INNER, join.type());
assertEquals("{{id}} = {{table2.id}}", join.value());
}
use of com.yahoo.elide.modelconfig.model.Table 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.modelconfig.model.Table 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.modelconfig.model.Table 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