use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class AggregationDataStoreTransactionTest method testMissingRequiredColumnFilter.
@Test
public void testMissingRequiredColumnFilter() throws Exception {
Type<PlayerStatsWithRequiredFilter> tableType = ClassType.of(PlayerStatsWithRequiredFilter.class);
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(PlayerStatsWithRequiredFilter.class);
SQLTable table = new SQLTable(new Namespace(DEFAULT_NAMESPACE), tableType, dictionary);
Query query = Query.builder().column(SQLMetricProjection.builder().name("highScore").build()).source(table).build();
AggregationDataStoreTransaction tx = new AggregationDataStoreTransaction(queryEngine, cache, queryLogger);
assertThrows(BadRequestException.class, () -> tx.addColumnFilterArguments(table, query, dictionary));
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class DefaultQueryValidatorTest method testMissingRequiredParameterInProjection.
@Test
public void testMissingRequiredParameterInProjection() {
SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
Query query = Query.builder().source(source).metricProjection(source.getMetricProjection("highScore")).dimensionProjection(source.getDimensionProjection("countryName")).build();
validateQuery(query, "Invalid operation: Argument 'format' for column 'countryName' is required");
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class SubqueryFilterSplitter method visitPredicate.
@Override
public SplitFilter visitPredicate(FilterPredicate filterPredicate) {
Type<?> tableType = filterPredicate.getEntityType();
String fieldName = filterPredicate.getField();
SQLTable table = metaDataStore.getTable(tableType);
List<Reference> references = parser.parse(table, table.getColumnProjection(fieldName));
boolean hasJoin = references.stream().anyMatch(ref -> ref.accept(new HasJoinVisitor()));
if (hasJoin) {
return SplitFilter.builder().outer(filterPredicate).build();
}
return SplitFilter.builder().inner(filterPredicate).build();
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class DailyAverageScorePerPeriod method resolve.
@Override
public QueryPlan resolve(Query query) {
SQLTable table = (SQLTable) query.getSource();
MetricProjection innerMetric = table.getMetricProjection("highScore");
TimeDimension innerTimeGrain = table.getTimeDimension("recordedDate");
Map<String, Argument> arguments = new HashMap<>();
arguments.put("grain", Argument.builder().name("grain").value(TimeGrain.DAY).build());
QueryPlan innerQuery = QueryPlan.builder().source(query.getSource()).metricProjection(innerMetric).timeDimensionProjection(new SQLTimeDimensionProjection(innerTimeGrain, innerTimeGrain.getTimezone(), "recordedDate_DAY", arguments, true)).build();
QueryPlan outerQuery = QueryPlan.builder().source(innerQuery).metricProjection(new DailyAverageScorePerPeriod(this, "AVG({{$highScore}})")).build();
return outerQuery;
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testWhereOnDimensionInProjectionNotRequiringJoin.
@Test
public void testWhereOnDimensionInProjectionNotRequiringJoin() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
FilterExpression having = new FilterPredicate(new Path(GameRevenue.class, dictionary, "revenue"), Operator.GT, Arrays.asList(9000));
FilterExpression where = new FilterPredicate(new Path(GameRevenue.class, dictionary, "category"), Operator.IN, Arrays.asList("foo"));
Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).dimensionProjection(gameRevenueTable.getDimensionProjection("countryIsoCode")).dimensionProjection(gameRevenueTable.getDimensionProjection("category")).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`.`category` AS `category` " + "FROM (SELECT MAX(`example_GameRevenue`.`revenue`) AS `INNER_AGG_XXX`," + "`example_GameRevenue`.`country_id` AS `country_id`," + "`example_GameRevenue`.`category` AS `category` " + "FROM `gameRevenue` AS `example_GameRevenue` " + "WHERE `example_GameRevenue`.`category` IN (:XXX) " + "GROUP BY `example_GameRevenue`.`country_id`, " + "`example_GameRevenue`.`category` ) " + "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`.`category` " + "HAVING MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) > :XXX\n";
compareQueryLists(expected, engine.explain(query));
testQueryExecution(query);
}
Aggregations