Search in sources :

Example 21 with Table

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

the class DynamicConfigValidator method validateInheritance.

private static void validateInheritance(ElideTableConfig tables, Table table, Set<Table> visited) {
    visited.add(table);
    if (!table.hasParent()) {
        return;
    }
    Table parent = table.getParent(tables);
    if (parent == null) {
        throw new IllegalStateException("Undefined model: " + table.getExtend() + " is used as a Parent(extend) for another model.");
    }
    if (visited.contains(parent)) {
        throw new IllegalStateException(String.format("Inheriting from table '%s' creates an illegal cyclic dependency.", parent.getName()));
    }
    validateInheritance(tables, parent, visited);
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table)

Example 22 with Table

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

the class DynamicConfigValidatorTest method testValidNamespace.

@Test
public void testValidNamespace() throws Exception {
    DynamicConfigValidator testClass = new DynamicConfigValidator(DefaultClassScanner.getInstance(), "src/test/resources/validator/valid");
    testClass.readConfigs();
    Table parent = testClass.getElideTableConfig().getTable("PlayerNamespace_PlayerStats");
    Table child = testClass.getElideTableConfig().getTable("PlayerNamespace_PlayerStatsChild");
    Table referred = testClass.getElideTableConfig().getTable("Country");
    assertEquals("PlayerNamespace", child.getNamespace());
    assertEquals("PlayerNamespace", parent.getNamespace());
    // Namespace in HJson "default".
    assertEquals("default", referred.getNamespace());
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table) Test(org.junit.jupiter.api.Test)

Example 23 with Table

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

the class DynamicConfigValidator method validateJoinedTablesDBConnectionName.

/**
 * Validates join clause does not refer to a Table which is not in the same DBConnection. If joined table is not
 * part of dynamic configuration, then ignore
 */
private static void validateJoinedTablesDBConnectionName(ElideTableConfig elideTableConfig) {
    for (Table table : elideTableConfig.getTables()) {
        if (!table.getJoins().isEmpty()) {
            Set<String> joinedTables = table.getJoins().stream().map(Join::getTo).collect(Collectors.toSet());
            Set<String> connections = elideTableConfig.getTables().stream().filter(t -> joinedTables.contains(t.getGlobalName())).map(Table::getDbConnectionName).collect(Collectors.toSet());
            if (connections.size() > 1 || (connections.size() == 1 && !Objects.equals(table.getDbConnectionName(), connections.iterator().next()))) {
                throw new IllegalStateException("DBConnection name mismatch between table: " + table.getName() + " and tables in its Join Clause.");
            }
        }
    }
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table)

Example 24 with Table

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

the class DynamicConfigValidator method populateInheritance.

private void populateInheritance(Table table, Set<Table> processed) {
    if (processed.contains(table)) {
        return;
    }
    processed.add(table);
    if (!table.hasParent()) {
        return;
    }
    Table parent = table.getParent(this.elideTableConfig);
    if (!processed.contains(parent)) {
        populateInheritance(parent, processed);
    }
    Map<String, Measure> measures = getInheritedMeasures(parent, attributesListToMap(table.getMeasures()));
    table.setMeasures(new ArrayList<>(measures.values()));
    Map<String, Dimension> dimensions = getInheritedDimensions(parent, attributesListToMap(table.getDimensions()));
    table.setDimensions(new ArrayList<>(dimensions.values()));
    Map<String, Join> joins = getInheritedJoins(parent, attributesListToMap(table.getJoins()));
    table.setJoins(new ArrayList<>(joins.values()));
    String schema = getInheritedSchema(parent, table.getSchema());
    table.setSchema(schema);
    String dbConnectionName = getInheritedConnection(parent, table.getDbConnectionName());
    table.setDbConnectionName(dbConnectionName);
    String sql = getInheritedSql(parent, table.getSql());
    table.setSql(sql);
    String tableName = getInheritedTable(parent, table.getTable());
    table.setTable(tableName);
    List<Argument> arguments = getInheritedArguments(parent, table.getArguments());
    table.setArguments(arguments);
// isFact, isHidden, ReadAccess, namespace have default Values in schema, so can not be inherited.
// Other properties (tags, cardinality, etc.) have been categorized as non-inheritable too.
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table) Argument(com.yahoo.elide.modelconfig.model.Argument) Measure(com.yahoo.elide.modelconfig.model.Measure) Join(com.yahoo.elide.modelconfig.model.Join) Dimension(com.yahoo.elide.modelconfig.model.Dimension)

Example 25 with Table

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

the class DynamicConfigValidatorTest method testValidInheritanceConfig.

@Test
public void testValidInheritanceConfig() throws Exception {
    DynamicConfigValidator testClass = new DynamicConfigValidator(DefaultClassScanner.getInstance(), "src/test/resources/validator/valid");
    testClass.readConfigs();
    Table parent = testClass.getElideTableConfig().getTable("PlayerNamespace_PlayerStats");
    Table child = testClass.getElideTableConfig().getTable("PlayerNamespace_PlayerStatsChild");
    // parent class dim + 3 new in child class + 2 overridden
    assertEquals(parent.getDimensions().size(), 4);
    assertEquals(child.getDimensions().size(), parent.getDimensions().size() + 3);
    // parent class measure + 1 new in child class
    assertEquals(parent.getMeasures().size(), 2);
    assertEquals(child.getMeasures().size(), parent.getMeasures().size() + 1);
    // parent class sql/table
    assertEquals("player_stats", child.getTable());
    assertNull(child.getSql());
    assertEquals("gamedb", child.getSchema());
    assertNull(child.getDbConnectionName());
    assertTrue(child.getIsFact());
    assertEquals(2, child.getArguments().size());
    assertEquals(parent.getArguments(), child.getArguments());
    // no new joins in child class, will inherit parent class joins
    assertEquals(parent.getJoins().size(), child.getJoins().size());
}
Also used : Table(com.yahoo.elide.modelconfig.model.Table) 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