use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class DefaultQueryValidatorTest method testInvalidTableArgument.
@Test
public void testInvalidTableArgument() {
SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
Map<String, Argument> tableArguments = new HashMap<>();
tableArguments.put("rating", Argument.builder().name("rating").value("SELECT * FROM FOO;").build());
Map<String, Argument> columnArguments = new HashMap<>();
columnArguments.put("format", Argument.builder().name("format").value("lower").build());
Query query = Query.builder().source(source).arguments(tableArguments).metricProjection(source.getMetricProjection("highScore")).dimensionProjection(source.getDimensionProjection("countryName", columnArguments)).build();
validateQuery(query, "Invalid operation: Argument 'rating' for table 'playerStatsView' has an invalid value: SELECT * FROM FOO;");
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class QueryKeyExtractorTest method testDuplicateFullQuery.
@Test
public void testDuplicateFullQuery() throws Exception {
// Build 1st Table
NamespaceConfig testNamespace = NamespaceConfig.builder().name("namespace1").build();
NamespacePackage testNamespacePackage = new NamespacePackage(testNamespace);
Table testTable = Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").namespace("namespace1").dimension(Dimension.builder().name("dim1").definition("{{dim1}}").type(Type.BOOLEAN).values(Collections.EMPTY_SET).tags(Collections.EMPTY_SET).build()).build();
TableType testType = new TableType(testTable, testNamespacePackage);
dictionary.bindEntity(testType);
SQLTable testSqlTable = new SQLTable(new Namespace(testNamespacePackage), testType, dictionary);
// Build 2nd Table
NamespaceConfig anotherTestNamespace = NamespaceConfig.builder().name("namespace2").build();
NamespacePackage anotherTestNamespacePackage = new NamespacePackage(anotherTestNamespace);
Table anotherTestTable = // Exactly same as testTable but different namespace
Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").namespace("namespace2").dimension(Dimension.builder().name("dim1").definition("{{dim1}}").type(Type.BOOLEAN).values(Collections.EMPTY_SET).tags(Collections.EMPTY_SET).build()).build();
TableType anotherTestType = new TableType(anotherTestTable, anotherTestNamespacePackage);
dictionary.bindEntity(anotherTestType);
SQLTable anotherTestSqlTable = new SQLTable(new Namespace(anotherTestNamespacePackage), anotherTestType, dictionary);
// Build Query and Test
Query query = Query.builder().source(testSqlTable).dimensionProjection(testSqlTable.getDimensionProjection("dim1")).pagination(new ImmutablePagination(0, 2, false, true)).build();
assertEquals(// table name
"namespace1_Table;" + // metrics
"{}" + // Group by
"{dim1;{}}" + // time dimensions
"{}" + // where
";" + // having
";" + // sort
";" + // pagination
"{0;2;1;}", QueryKeyExtractor.extractKey(query));
Query anotherQuery = Query.builder().source(anotherTestSqlTable).dimensionProjection(anotherTestSqlTable.getDimensionProjection("dim1")).pagination(new ImmutablePagination(0, 2, false, true)).build();
assertEquals(// table name
"namespace2_Table;" + // metrics
"{}" + // Group by
"{dim1;{}}" + // time dimensions
"{}" + // where
";" + // having
";" + // sort
";" + // pagination
"{0;2;1;}", QueryKeyExtractor.extractKey(anotherQuery));
assertNotEquals(QueryKeyExtractor.extractKey(anotherQuery), QueryKeyExtractor.extractKey(query));
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class ColumnArgumentValidator method verifyLogicalReference.
private void verifyLogicalReference(LogicalReference reference) {
SQLTable sqlTable = (SQLTable) reference.getSource();
ColumnProjection columnProj = reference.getColumn();
// This will have dependent column's defined arguments merged with pinned arguments used to invoke this column.
Map<String, Argument> mergedArguments = columnProj.getArguments();
Column refColumn = sqlTable.getColumn(Column.class, columnProj.getName());
verifyPinnedArguments(mergedArguments, refColumn, String.format(errorMsgPrefix + "Type mismatch of Fixed value provided for Dependent Column: '%s' in table: '%s'. ", refColumn.getName(), sqlTable.getName()));
refColumn.getArgumentDefinitions().forEach(argDef -> {
String argName = argDef.getName();
if (column.hasArgumentDefinition(argName)) {
if (argDef.getType() != column.getArgumentDefinition(argName).getType()) {
throw new IllegalStateException(String.format(errorMsgPrefix + "Argument type mismatch. Dependent Column: '%s' in table: '%s' has same" + " Argument: '%s' with type '%s'.", refColumn.getName(), sqlTable.getName(), argName, argDef.getType()));
}
} else if (StringUtils.isBlank(argDef.getDefaultValue().toString()) && StringUtils.isBlank(mergedArguments.get(argName).getValue().toString())) {
throw new IllegalStateException(String.format(errorMsgPrefix + "Argument '%s' with type '%s' is not defined but is required for" + " Dependent Column: '%s' in table: '%s'.", argName, argDef.getType(), refColumn.getName(), sqlTable.getName()));
}
});
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class TemplateConfigValidator method validate.
@Override
public void validate(Map<String, ConfigFile> resourceMap) {
MetaDataStore metaDataStore = rebuildMetaDataStore(resourceMap);
metaDataStore.getTables().forEach(table -> {
SQLTable sqlTable = (SQLTable) table;
checkForCycles(sqlTable, metaDataStore);
TableArgumentValidator tableArgValidator = new TableArgumentValidator(metaDataStore, sqlTable);
tableArgValidator.validate();
sqlTable.getAllColumns().forEach(column -> {
ColumnArgumentValidator colArgValidator = new ColumnArgumentValidator(metaDataStore, sqlTable, column);
colArgValidator.validate();
});
});
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class AggregationDataStoreTransactionTest method testMissingRequiredTableFilter.
@Test
public void testMissingRequiredTableFilter() {
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(PlayerStatsWithRequiredFilter.class);
Table table = new SQLTable(new Namespace(DEFAULT_NAMESPACE), ClassType.of(PlayerStatsWithRequiredFilter.class), dictionary);
AggregationDataStoreTransaction tx = new AggregationDataStoreTransaction(queryEngine, cache, queryLogger);
assertThrows(BadRequestException.class, () -> tx.addTableFilterArguments(table, query, dictionary));
}
Aggregations