Search in sources :

Example 1 with Table

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));
}
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 2 with Table

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());
}
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 3 with Table

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));
}
Also used : NamespaceConfig(com.yahoo.elide.modelconfig.model.NamespaceConfig) Table(com.yahoo.elide.modelconfig.model.Table) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) TableType(com.yahoo.elide.datastores.aggregation.dynamic.TableType) Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) ImmutablePagination(com.yahoo.elide.datastores.aggregation.query.ImmutablePagination) NamespacePackage(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 4 with Table

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());
}
Also used : Field(com.yahoo.elide.core.type.Field) Table(com.yahoo.elide.modelconfig.model.Table) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) ColumnMeta(com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta) Test(org.junit.jupiter.api.Test)

Example 5 with Table

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());
}
Also used : Field(com.yahoo.elide.core.type.Field) Table(com.yahoo.elide.modelconfig.model.Table) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) ColumnMeta(com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta) MetricFormula(com.yahoo.elide.datastores.aggregation.annotation.MetricFormula) ReadPermission(com.yahoo.elide.annotation.ReadPermission) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

Table (com.yahoo.elide.modelconfig.model.Table)43 Test (org.junit.jupiter.api.Test)39 HashSet (java.util.HashSet)23 MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)17 DefaultQueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)16 QueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.QueryPlanMerger)16 SQLQueryEngine (com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine)16 FromTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable)16 Field (com.yahoo.elide.core.type.Field)12 ColumnMeta (com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta)6 ReadPermission (com.yahoo.elide.annotation.ReadPermission)4 BadRequestException (com.yahoo.elide.core.exceptions.BadRequestException)3 Include (com.yahoo.elide.annotation.Include)2 DimensionFormula (com.yahoo.elide.datastores.aggregation.annotation.DimensionFormula)2 MetricFormula (com.yahoo.elide.datastores.aggregation.annotation.MetricFormula)2 TableMeta (com.yahoo.elide.datastores.aggregation.annotation.TableMeta)2 Temporal (com.yahoo.elide.datastores.aggregation.annotation.Temporal)2 NamespacePackage (com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage)1 TableType (com.yahoo.elide.datastores.aggregation.dynamic.TableType)1 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)1