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