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