Search in sources :

Example 16 with Table

use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.

the class TableArgumentValidatorTest method testTableArgsTypeMismatchForJoinTable.

@Test
public void testTableArgsTypeMismatchForJoinTable() {
    Table mainTable = mainTableBuilder.join(Join.builder().name("join").namespace("namespace").to("JoinTable").definition("start {{$$table.args.mainArg1}} end").build()).build();
    Set<Table> tables = new HashSet<>();
    tables.add(mainTable);
    tables.add(Table.builder().name("JoinTable").namespace("namespace").argument(Argument.builder().name("mainArg1").type(Type.TEXT).values(Collections.emptySet()).defaultValue("").build()).build());
    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 type mismatch. Join table: 'namespace_JoinTable' has same Argument: 'mainArg1' with type 'TEXT'.", 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 17 with Table

use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.

the class TableArgumentValidatorTest method testUndefinedTableArgsInColumnDefinition.

@Test
public void testUndefinedTableArgsInColumnDefinition() {
    Table mainTable = mainTableBuilder.dimension(Dimension.builder().name("dim1").type(Type.BOOLEAN).values(Collections.emptySet()).tags(Collections.emptySet()).definition("start {{$$table.args.mainArg1}} blah {{$$table.args.mainArg2}} end").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. Argument 'mainArg2' is not defined but found '{{$$table.args.mainArg2}}' in definition of column: 'dim1'.", 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 18 with Table

use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.

the class DynamicConfigValidatorTest method testDuplicateArgumentNameInTableFilter.

@Test
public void testDuplicateArgumentNameInTableFilter() throws Exception {
    DynamicConfigValidator testClass = new DynamicConfigValidator(DefaultClassScanner.getInstance(), "src/test/resources/validator/valid");
    testClass.readConfigs();
    Table playerStatsTable = testClass.getElideTableConfig().getTable("PlayerNamespace_PlayerStats");
    // PlayerStats table already has a filter argument 'code' with type 'TEXT'.
    playerStatsTable.getArguments().add(Argument.builder().name("code").type(Type.TEXT).build());
    Exception e = assertThrows(IllegalStateException.class, () -> testClass.validateConfigs());
    assertEquals("Multiple Arguments found with the same name: code", e.getMessage());
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table) BadRequestException(com.yahoo.elide.core.exceptions.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 19 with Table

use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.

the class DynamicConfigValidatorTest method testDuplicateArgumentName.

@Test
public void testDuplicateArgumentName() throws Exception {
    DynamicConfigValidator testClass = new DynamicConfigValidator(DefaultClassScanner.getInstance(), "src/test/resources/validator/valid");
    testClass.readConfigs();
    Table playerStatsTable = testClass.getElideTableConfig().getTable("PlayerNamespace_PlayerStats");
    // PlayerStats table already has argument 'countryCode' with type 'TEXT'.
    // Adding another argument 'countryCode' with type 'INTEGER'.
    playerStatsTable.getArguments().add(Argument.builder().name("countryCode").type(Type.INTEGER).build());
    Exception e = assertThrows(IllegalStateException.class, () -> testClass.validateConfigs());
    assertEquals("Multiple Arguments found with the same name: countryCode", e.getMessage());
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table) BadRequestException(com.yahoo.elide.core.exceptions.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 20 with Table

use of com.yahoo.elide.modelconfig.model.Table in project elide by yahoo.

the class DynamicConfigValidator method validateTableConfig.

/**
 * Validate table configs.
 * @return boolean true if all provided table properties passes validation
 */
private boolean validateTableConfig() {
    Set<String> extractedFieldChecks = new HashSet<>();
    Set<String> extractedTableChecks = new HashSet<>();
    PermissionExpressionVisitor visitor = new PermissionExpressionVisitor();
    for (Table table : elideTableConfig.getTables()) {
        validateSql(table.getSql());
        validateArguments(table, table.getArguments(), table.getFilterTemplate());
        // TODO - once tables support versions - replace NO_VERSION with apiVersion
        validateNamespaceExists(table.getNamespace(), NO_VERSION);
        Set<String> tableFields = new HashSet<>();
        table.getDimensions().forEach(dim -> {
            validateFieldNameUniqueness(tableFields, dim.getName(), table.getName());
            validateSql(dim.getDefinition());
            validateTableSource(dim.getTableSource());
            validateArguments(table, dim.getArguments(), dim.getFilterTemplate());
            extractChecksFromExpr(dim.getReadAccess(), extractedFieldChecks, visitor);
        });
        table.getMeasures().forEach(measure -> {
            validateFieldNameUniqueness(tableFields, measure.getName(), table.getName());
            validateSql(measure.getDefinition());
            validateArguments(table, measure.getArguments(), measure.getFilterTemplate());
            extractChecksFromExpr(measure.getReadAccess(), extractedFieldChecks, visitor);
        });
        table.getJoins().forEach(join -> {
            validateFieldNameUniqueness(tableFields, join.getName(), table.getName());
            validateSql(join.getDefinition());
            validateModelExists(join.getTo());
            // TODO - once tables support versions - replace NO_VERSION with apiVersion
            validateNamespaceExists(join.getNamespace(), NO_VERSION);
        });
        extractChecksFromExpr(table.getReadAccess(), extractedTableChecks, visitor);
    }
    validateChecks(extractedTableChecks, extractedFieldChecks);
    return true;
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table) HashSet(java.util.HashSet)

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