use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class AggregationDataStoreTransaction method addColumnFilterArguments.
@VisibleForTesting
Query addColumnFilterArguments(Table table, Query query, EntityDictionary dictionary) {
Query.QueryBuilder queryBuilder = Query.builder();
query.getColumnProjections().stream().forEach(projection -> {
Column column = table.getColumn(Column.class, projection.getName());
FilterExpression requiredFilter = column.getRequiredFilter(dictionary);
if (requiredFilter != null) {
Map<String, Argument> allArguments = validateRequiredFilter(requiredFilter, query, column);
if (projection.getArguments() != null) {
allArguments.putAll(projection.getArguments());
}
queryBuilder.column(projection.withArguments(allArguments));
} else {
queryBuilder.column(projection);
}
});
return queryBuilder.arguments(query.getArguments()).havingFilter(query.getHavingFilter()).whereFilter(query.getWhereFilter()).sorting(query.getSorting()).pagination(query.getPagination()).bypassingCache(query.isBypassingCache()).source(query.getSource()).scope(query.getScope()).build();
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class DefaultQueryValidator method validateColumnArguments.
protected void validateColumnArguments(Query query, ColumnProjection projection) {
SQLTable table = (SQLTable) query.getSource();
Column column = table.getColumn(Column.class, projection.getName());
column.getArgumentDefinitions().forEach(columnArgument -> {
Argument clientArgument = projection.getArguments().get(columnArgument.getName());
validateArgument(Optional.ofNullable(clientArgument), columnArgument, "column '" + projection.getAlias() + "'");
});
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class Queryable method getFilterProjections.
default List<ColumnProjection> getFilterProjections(FilterExpression expression) {
List<ColumnProjection> results = new ArrayList<>();
if (expression == null) {
return results;
}
Collection<FilterPredicate> predicates = expression.accept(new PredicateExtractionVisitor());
predicates.stream().forEach((predicate -> {
Map<String, Argument> arguments = new HashMap<>();
predicate.getPath().lastElement().get().getArguments().forEach(argument -> arguments.put(argument.getName(), argument));
ColumnProjection projection = getSource().getColumnProjection(predicate.getField(), arguments);
results.add(projection);
}));
return results;
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class Queryable method extractFilterProjections.
/**
* Converts a filter expression into a set of ColumnProjections.
* @param query The parent query.
* @param expression The filter expression to extract.
* @return A set of zero or more column projections with their arguments.
*/
static Set<ColumnProjection> extractFilterProjections(Queryable query, FilterExpression expression) {
if (expression == null) {
return new LinkedHashSet<>();
}
Collection<FilterPredicate> predicates = expression.accept(new PredicateExtractionVisitor());
Set<ColumnProjection> filterProjections = new LinkedHashSet<>();
predicates.stream().forEach((predicate -> {
Map<String, Argument> arguments = new HashMap<>();
predicate.getPath().lastElement().get().getArguments().forEach(argument -> arguments.put(argument.getName(), argument));
ColumnProjection projection = query.getSource().getColumnProjection(predicate.getField(), arguments);
if (projection != null) {
filterProjections.add(projection);
}
}));
return filterProjections;
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testWhereOnTimeDimensionInProjectionNotRequiringJoinWithDefaultMatchingArguments.
@Test
public void testWhereOnTimeDimensionInProjectionNotRequiringJoinWithDefaultMatchingArguments() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
Set<Argument> arguments = new HashSet<>();
arguments.add(Argument.builder().name("grain").value("DAY").build());
FilterExpression having = new FilterPredicate(new Path(GameRevenue.class, dictionary, "revenue"), Operator.GT, Arrays.asList(9000));
FilterExpression where = new FilterPredicate(new Path(GameRevenue.class, dictionary, "saleDate", "saleDate", arguments), Operator.IN, Arrays.asList(new Day(new Date())));
Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).dimensionProjection(gameRevenueTable.getDimensionProjection("countryIsoCode")).timeDimensionProjection(gameRevenueTable.getTimeDimensionProjection("saleDate")).havingFilter(having).whereFilter(where).build();
String expected = "SELECT MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) AS `revenue`," + "`example_GameRevenue_XXX_country_XXX`.`iso_code` AS `countryIsoCode`," + "`example_GameRevenue_XXX`.`saleDate` AS `saleDate` " + "FROM (SELECT MAX(`example_GameRevenue`.`revenue`) AS `INNER_AGG_XXX`," + "`example_GameRevenue`.`country_id` AS `country_id`," + "PARSEDATETIME(FORMATDATETIME(`example_GameRevenue`.`saleDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') AS `saleDate` " + "FROM `gameRevenue` AS `example_GameRevenue` " + "WHERE PARSEDATETIME(FORMATDATETIME(`example_GameRevenue`.`saleDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') IN (:XXX) " + "GROUP BY `example_GameRevenue`.`country_id`, " + "PARSEDATETIME(FORMATDATETIME(`example_GameRevenue`.`saleDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') ) " + "AS `example_GameRevenue_XXX` " + "LEFT OUTER JOIN `countries` AS `example_GameRevenue_XXX_country_XXX` " + "ON `example_GameRevenue_XXX`.`country_id` = `example_GameRevenue_XXX_country_XXX`.`id` " + "GROUP BY `example_GameRevenue_XXX_country_XXX`.`iso_code`, " + "`example_GameRevenue_XXX`.`saleDate` " + "HAVING MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) > :XXX\n";
compareQueryLists(expected, engine.explain(query));
testQueryExecution(query);
}
Aggregations