Search in sources :

Example 11 with Table

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())));
}
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) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 12 with Table

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

Example 13 with Table

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

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

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

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