use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class CurrencyRate method testSqlHelper.
@Test
public void testSqlHelper() {
Map<String, Argument> revenueArg = new HashMap<>();
revenueArg.put("format", Argument.builder().name("format").value("11D00").build());
SQLMetricProjection revenueUsingSqlHelper = (SQLMetricProjection) revenueFactTable.getMetricProjection("revenueUsingSqlHelper", "revenueUsingSqlHelper", revenueArg);
SQLMetricProjection impressionsPerUSD = (SQLMetricProjection) revenueFactTable.getMetricProjection("impressionsPerUSD");
Map<String, Argument> impressionsPerUSDArg = new HashMap<>();
impressionsPerUSDArg.put("format", Argument.builder().name("format").value("11D00").build());
SQLMetricProjection impressionsPerUSDWithArg = (SQLMetricProjection) revenueFactTable.getMetricProjection("impressionsPerUSD", "impressionsPerUSDWithArg", impressionsPerUSDArg);
// impressionsPerUSD2 invokes 'revenueUsingSqlHelper' instead of 'revenue'.
SQLMetricProjection impressionsPerUSD2 = (SQLMetricProjection) revenueFactTable.getMetricProjection("impressionsPerUSD2");
Query query = Query.builder().source(revenueFactTable).metricProjection(revenueUsingSqlHelper).metricProjection(impressionsPerUSD).metricProjection(impressionsPerUSDWithArg).metricProjection(impressionsPerUSD2).arguments(queryArgs).build();
Query.QueryBuilder builder = Query.builder().source(query.getSource()).metricProjections(query.getMetricProjections()).arguments(query.getArguments());
Query expandedQuery = addHiddenProjections(metaDataStore, builder, query).build();
// definition: TO_CHAR(SUM({{$revenue}}) * {{sql from='rate' column='conversionRate[format:9999D0000]'}}, {{$$column.args.format}})
// -> value of 'format' argument is passed in the query for "revenueUsingSqlHelper" column and same is used for
// resolving this column.
// -> pinned value (9999D0000) of 'format' argument in SQL helper is used while resolving referenced column "rate.conversionRate".
assertEquals("TO_CHAR(SUM(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`revenue`)" + " * TO_CHAR(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`conversion_rate`, 9999D0000), 11D00)", revenueUsingSqlHelper.toSQL(expandedQuery, metaDataStore));
// definition: TO_CHAR({{sql column='impressions[aggregation:SUM]'}} / {{sql column='revenue[format:99999D00000]'}}, {{$$table.args.format}})
// -> {{$$table.args.format}} is resolved using query argument 'format' (999999D000000).
// -> pinned value (SUM) of 'aggregation' argument in SQL helper is used while resolving invoked column "impressions".
// -> pinned value (99999D00000) of 'format' argument in SQL helper is used while resolving invoked column "revenue".
// -> revenue definition is : TO_CHAR(SUM({{$revenue}}) * {{rate.conversionRate}}, {{$$column.args.format}}),
// Available value of 'format' argument in "revenue" column is passed to joined table's "conversionRate" column.
assertEquals("TO_CHAR(SUM(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`impressions`)" + " / TO_CHAR(SUM(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`revenue`)" + " * TO_CHAR(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`conversion_rate`, 99999D00000), 99999D00000), 999999D000000)", impressionsPerUSD.toSQL(expandedQuery, metaDataStore));
// -> Even 'format' is passed in query column args, pinned value (9999D0000) of 'format' argument in SQL helper is used while
// resolving "revenue" column and same is passed to joined table's "conversionRate" column.
assertEquals("TO_CHAR(SUM(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`impressions`)" + " / TO_CHAR(SUM(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`revenue`)" + " * TO_CHAR(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`conversion_rate`, 99999D00000), 99999D00000), 999999D000000)", impressionsPerUSDWithArg.toSQL(expandedQuery, metaDataStore));
// definition: TO_CHAR({{sql column='impressions[aggregation:SUM]'}} / {{sql column='revenueUsingSqlHelper[format:99999D00000]'}}, {{$$table.args.format}})
// -> As "rate.conversionRate" is invoked using SQL helper from "revenue" column, this uses the fixed value(9999D0000) of
// 'format' argument provided in definition of "revenueUsingSqlHelper" column.
assertEquals("TO_CHAR(SUM(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`impressions`)" + " / TO_CHAR(SUM(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`revenue`)" + " * TO_CHAR(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`conversion_rate`, 9999D0000), 99999D00000), 999999D000000)", impressionsPerUSD2.toSQL(expandedQuery, metaDataStore));
}
use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class DefaultQueryValidatorTest method testInvalidColumnArgument.
@Test
public void testInvalidColumnArgument() {
SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
Map<String, Argument> argumentMap = new HashMap<>();
argumentMap.put("format", Argument.builder().name("format").value(";").build());
Query query = Query.builder().source(source).metricProjection(source.getMetricProjection("highScore")).dimensionProjection(source.getDimensionProjection("countryName", "countryName", argumentMap)).build();
validateQuery(query, "Invalid operation: Argument 'format' for column 'countryName' must match one of these values: [lower, upper]");
}
use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class DefaultQueryValidatorTest method testSortingOnNotQueriedDimension.
@Test
public void testSortingOnNotQueriedDimension() {
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("countryIsoCode", Sorting.SortOrder.asc);
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("lowScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).build();
validateQuery(query, "Invalid operation: Can not sort on countryIsoCode as it is not present in query");
}
use of com.yahoo.elide.datastores.aggregation.query.Query 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.query.Query in project elide by yahoo.
the class EntityProjectionTranslatorTest method testWherePromotion.
@Test
public void testWherePromotion() throws ParseException {
FilterExpression originalFilter = filterParser.parseFilterExpression("overallRating==Good,lowScore[foo:bar]<45", playerStatsType, false);
EntityProjection projection = basicProjection.copyOf().filterExpression(originalFilter).build();
EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, projection, scope, true);
Query query = translator.getQuery();
SplitFilterExpressionVisitor visitor = new SplitFilterExpressionVisitor(playerStatsTable);
FilterConstraints constraints = originalFilter.accept(visitor);
FilterExpression whereFilter = constraints.getWhereExpression();
FilterExpression havingFilter = constraints.getHavingExpression();
assertEquals(whereFilter, query.getWhereFilter());
assertEquals(havingFilter, query.getHavingFilter());
}
Aggregations