use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class SQLQueryEngine method getTableVersion.
@Override
public String getTableVersion(Table table, Transaction transaction) {
String tableVersion = null;
SQLTable sqlTable = (SQLTable) table;
Type<?> tableClass = metadataDictionary.getEntityClass(table.getName(), table.getVersion());
VersionQuery versionAnnotation = tableClass.getAnnotation(VersionQuery.class);
if (versionAnnotation != null) {
String versionQueryString = versionAnnotation.sql();
SqlTransaction sqlTransaction = (SqlTransaction) transaction;
ConnectionDetails details = sqlTable.getConnectionDetails();
DataSource dataSource = details.getDataSource();
NamedParamPreparedStatement stmt = sqlTransaction.initializeStatement(versionQueryString, dataSource);
tableVersion = CoerceUtil.coerce(runQuery(stmt, versionQueryString, SINGLE_RESULT_MAPPER), String.class);
}
return tableVersion;
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class SQLQueryEngine method verifyMetaData.
@Override
protected void verifyMetaData(MetaDataStore metaDataStore) {
metaDataStore.getTables().forEach(table -> {
SQLTable sqlTable = (SQLTable) table;
checkForCycles(sqlTable);
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 SQLQueryEngine method expandMetricQueryPlans.
/**
* Transforms a client query into a potentially nested/complex query by expanding each metric into
* its respective query plan - and then merging the plans together into a consolidated query.
* @param query The client query.
* @return A query that reflects each metric's individual query plan.
*/
private Query expandMetricQueryPlans(Query query) {
// Expand each metric into its own query plan.
List<QueryPlan> toMerge = query.getMetricProjections().stream().map(projection -> projection.resolve(query)).collect(Collectors.toList());
// Merge all the queries together.
List<QueryPlan> mergedPlans = merger.merge(toMerge);
// TODO - Support joins across plans rather than rejecting plans that don't merge.
if (mergedPlans.size() != 1) {
throw new UnsupportedOperationException("Incompatible metrics in client query. Cannot merge " + "into a single query");
}
QueryPlan mergedPlan = mergedPlans.get(0);
QueryPlanTranslator queryPlanTranslator = new QueryPlanTranslator(query, metaDataStore, merger);
Query merged = (mergedPlan == null) ? QueryPlanTranslator.addHiddenProjections(metaDataStore, query).build() : queryPlanTranslator.translate(mergedPlan);
for (Optimizer optimizer : optimizers) {
SQLTable table = (SQLTable) query.getSource();
// override table hints.
if (table.getHints().contains(optimizer.negateHint())) {
continue;
}
if (!table.getHints().contains(optimizer.hint())) {
continue;
}
if (optimizer.canOptimize(merged)) {
merged = optimizer.optimize(merged);
}
}
return merged;
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class DefaultQueryValidator method validateQueryArguments.
@Override
public void validateQueryArguments(Query query) {
SQLTable table = (SQLTable) query.getSource();
table.getArgumentDefinitions().forEach(tableArgument -> {
Argument clientArgument = query.getArguments().get(tableArgument.getName());
validateArgument(Optional.ofNullable(clientArgument), tableArgument, "table '" + query.getSource().getName() + "'");
});
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class DefaultQueryValidator method validatePredicate.
protected void validatePredicate(Query query, FilterPredicate predicate) {
SQLTable table = (SQLTable) query.getSource();
Set<ColumnProjection> projections = extractFilterProjections(query, predicate);
if (projections.isEmpty()) {
return;
}
ColumnProjection projection = projections.iterator().next();
validateColumn(query, projection);
Column column = table.getColumn(Column.class, projection.getName());
if (column.getValueType().equals(ValueType.ID)) {
throw new InvalidOperationException("Filtering by ID is not supported on " + query.getSource().getName());
}
if (column.getValues() == null || column.getValues().isEmpty()) {
return;
}
if (REGEX_OPERATORS.contains(predicate.getOperator())) {
return;
}
predicate.getValues().forEach(value -> {
if (!column.getValues().contains(value)) {
throw new InvalidOperationException(String.format("Column '%s' values must match one of these values: %s", projection.getAlias(), column.getValues()));
}
});
}
Aggregations