use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.
the class ColumnArgumentValidatorTest method testMissingRequiredColumnArgsForDepenedentColumnCase1.
@Test
public void testMissingRequiredColumnArgsForDepenedentColumnCase1() {
Table mainTable = mainTableBuilder.dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$column.args.mainArg1}} blah {{dim2}} end").argument(mainArg1).build()).dimension(Dimension.builder().name("dim2").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("{{$dim2}} blah {{$$column.args.dependentArg1}} end").argument(Argument.builder().name("dependentArg1").type(Type.INTEGER).values(Collections.emptySet()).defaultValue("").build()).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 column arguments for column: dim1 in table: namespace_MainTable. Argument 'dependentArg1' with type 'INTEGER' is not defined but is" + " required for Dependent Column: 'dim2' in table: 'namespace_MainTable'.", e.getMessage());
// If 'dim2' is invoked using SQL helper, must not complain.
mainTable = mainTableBuilder.dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$column.args.mainArg1}} blah {{sql column='dim2[dependentArg1:123]'}} end").argument(mainArg1).build()).dimension(Dimension.builder().name("dim2").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("{{$dim2}} blah {{$$column.args.dependentArg1}} end").argument(Argument.builder().name("dependentArg1").type(Type.INTEGER).values(Collections.emptySet()).defaultValue("").build()).build()).build();
tables = new HashSet<>();
tables.add(mainTable);
MetaDataStore metaDataStore1 = new MetaDataStore(DefaultClassScanner.getInstance(), tables, this.namespaceConfigs, true);
assertDoesNotThrow(() -> new SQLQueryEngine(metaDataStore1, connectionLookup, optimizers, merger, queryValidator));
}
use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.
the class ColumnArgumentValidatorTest method testUndefinedColumnArgsInColumnDefinition.
@Test
public void testUndefinedColumnArgsInColumnDefinition() {
Table mainTable = mainTableBuilder.dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$column.args.mainArg1}} blah {{$$column.args.mainArg2}} end").argument(mainArg1).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 column arguments for column: dim1 in table: namespace_MainTable. Argument 'mainArg2' is not defined but found '{{$$column.args.mainArg2}}'.", e.getMessage());
}
use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.
the class QueryKeyExtractorTest method testDuplicateFullQuery.
@Test
public void testDuplicateFullQuery() throws Exception {
// Build 1st Table
NamespaceConfig testNamespace = NamespaceConfig.builder().name("namespace1").build();
NamespacePackage testNamespacePackage = new NamespacePackage(testNamespace);
Table testTable = Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").namespace("namespace1").dimension(Dimension.builder().name("dim1").definition("{{dim1}}").type(Type.BOOLEAN).values(Collections.EMPTY_SET).tags(Collections.EMPTY_SET).build()).build();
TableType testType = new TableType(testTable, testNamespacePackage);
dictionary.bindEntity(testType);
SQLTable testSqlTable = new SQLTable(new Namespace(testNamespacePackage), testType, dictionary);
// Build 2nd Table
NamespaceConfig anotherTestNamespace = NamespaceConfig.builder().name("namespace2").build();
NamespacePackage anotherTestNamespacePackage = new NamespacePackage(anotherTestNamespace);
Table anotherTestTable = // Exactly same as testTable but different namespace
Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").namespace("namespace2").dimension(Dimension.builder().name("dim1").definition("{{dim1}}").type(Type.BOOLEAN).values(Collections.EMPTY_SET).tags(Collections.EMPTY_SET).build()).build();
TableType anotherTestType = new TableType(anotherTestTable, anotherTestNamespacePackage);
dictionary.bindEntity(anotherTestType);
SQLTable anotherTestSqlTable = new SQLTable(new Namespace(anotherTestNamespacePackage), anotherTestType, dictionary);
// Build Query and Test
Query query = Query.builder().source(testSqlTable).dimensionProjection(testSqlTable.getDimensionProjection("dim1")).pagination(new ImmutablePagination(0, 2, false, true)).build();
assertEquals(// table name
"namespace1_Table;" + // metrics
"{}" + // Group by
"{dim1;{}}" + // time dimensions
"{}" + // where
";" + // having
";" + // sort
";" + // pagination
"{0;2;1;}", QueryKeyExtractor.extractKey(query));
Query anotherQuery = Query.builder().source(anotherTestSqlTable).dimensionProjection(anotherTestSqlTable.getDimensionProjection("dim1")).pagination(new ImmutablePagination(0, 2, false, true)).build();
assertEquals(// table name
"namespace2_Table;" + // metrics
"{}" + // Group by
"{dim1;{}}" + // time dimensions
"{}" + // where
";" + // having
";" + // sort
";" + // pagination
"{0;2;1;}", QueryKeyExtractor.extractKey(anotherQuery));
assertNotEquals(QueryKeyExtractor.extractKey(anotherQuery), QueryKeyExtractor.extractKey(query));
}
use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.
the class TableTypeTest method testHiddenDimension.
@Test
void testHiddenDimension() throws Exception {
Table testTable = Table.builder().table("table1").name("Table").dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).hidden(true).build()).build();
TableType testType = new TableType(testTable);
Field field = testType.getDeclaredField("dim1");
assertNotNull(field);
ColumnMeta columnMeta = field.getAnnotation(ColumnMeta.class);
assertNotNull(columnMeta);
assertTrue(columnMeta.isHidden());
}
use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.
the class TableTypeTest method testMeasureAnnotations.
@Test
void testMeasureAnnotations() throws Exception {
Set<String> tags = new HashSet<>(Arrays.asList("tag1", "tag2"));
Table testTable = Table.builder().table("table1").name("Table").measure(Measure.builder().type(Type.MONEY).category("category1").definition("SUM{{ price}}").hidden(false).friendlyName("Price").name("price").readAccess("Admin").description("A measure").tags(tags).build()).build();
TableType testType = new TableType(testTable);
Field field = testType.getDeclaredField("price");
assertNotNull(field);
ReadPermission readPermission = field.getAnnotation(ReadPermission.class);
assertEquals("Admin", readPermission.expression());
ColumnMeta columnMeta = field.getAnnotation(ColumnMeta.class);
assertEquals("A measure", columnMeta.description());
assertEquals("category1", columnMeta.category());
assertEquals("Price", columnMeta.friendlyName());
assertEquals(CardinalitySize.UNKNOWN, columnMeta.size());
assertEquals(tags, new HashSet<>(Arrays.asList(columnMeta.tags())));
MetricFormula metricFormula = field.getAnnotation(MetricFormula.class);
assertEquals("SUM{{price}}", metricFormula.value());
assertEquals(DefaultMetricProjectionMaker.class, metricFormula.maker());
}
Aggregations