use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class JoinJoinTable method testArgumentsInJoinExprCase3.
// Both dim4 and dim5 passes same value for join expression's argument 'exprArg'
// dim4 and dim5 passes different value for join table's column argument 'joinArg'
// 2 Join expressions are generated.
@Test
void testArgumentsInJoinExprCase3() {
Map<String, Argument> dim4Arg = new HashMap<>();
dim4Arg.put("exprArg", Argument.builder().name("exprArg").value("same").build());
dim4Arg.put("joinArg", Argument.builder().name("joinArg").value("foo4").build());
SQLDimensionProjection dim4 = (SQLDimensionProjection) table.getDimensionProjection("dim4", "dim4", dim4Arg);
Map<String, Argument> dim5Arg = new HashMap<>();
dim5Arg.put("exprArg", Argument.builder().name("exprArg").value("same").build());
dim5Arg.put("joinArg", Argument.builder().name("joinArg").value("foo5").build());
SQLDimensionProjection dim5 = (SQLDimensionProjection) table.getDimensionProjection("dim5", "dim5", dim5Arg);
Query query = Query.builder().source(table).dimensionProjection(dim4).dimensionProjection(dim5).arguments(emptyMap()).build();
String generatedSql = engine.explain(query).get(0);
String expectedSQL = "SELECT " + NL + " DISTINCT `MainTable_join2_201179732`.`dim1` AS `dim4`," + NL + " `MainTable_join2_201179856`.`dim1` AS `dim5` " + NL + "FROM " + NL + " `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + " `join_table` AS `MainTable_join2_201179732` " + NL + "ON " + NL + " value = 'same' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_201179732`.`dim4` - 'foo4' " + "LEFT OUTER JOIN " + NL + " `join_table` AS `MainTable_join2_201179856` " + NL + "ON " + NL + " value = 'same' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_201179856`.`dim4` - 'foo5' ";
assertEquals(formatExpected(expectedSQL), formatGenerated(generatedSql));
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class JoinJoinTable method testArgumentsInJoinExprCase2b.
// dim4x and dim5x passes different value for join expression's argument 'exprArg'
// 1 Join expression is generated as they invoke dim4 and dim5 using sql helper with same value
@Test
void testArgumentsInJoinExprCase2b() {
Map<String, Argument> dim4Arg = new HashMap<>();
dim4Arg.put("exprArg", Argument.builder().name("exprArg").value("value4").build());
SQLDimensionProjection dim4x = (SQLDimensionProjection) table.getDimensionProjection("dim4x", "dim4x", dim4Arg);
Map<String, Argument> dim5Arg = new HashMap<>();
dim5Arg.put("exprArg", Argument.builder().name("exprArg").value("value5").build());
SQLDimensionProjection dim5x = (SQLDimensionProjection) table.getDimensionProjection("dim5x", "dim5x", dim5Arg);
Query query = Query.builder().source(table).dimensionProjection(dim4x).dimensionProjection(dim5x).arguments(emptyMap()).build();
String generatedSql = engine.explain(query).get(0);
String expectedSQL = "SELECT " + NL + " DISTINCT `MainTable_join2_156385021`.`dim1` - 'value4' AS `dim4x`," + NL + " `MainTable_join2_156385021`.`dim1` - 'value5' AS `dim5x` " + NL + "FROM " + NL + " `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + " `join_table` AS `MainTable_join2_156385021` " + NL + "ON " + NL + " value = 'fixedExpr' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_156385021`.`dim4` - 'fixedArg' ";
assertEquals(formatExpected(expectedSQL), formatGenerated(generatedSql));
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class QueryEngineTest method testMultipleTimeGrainsSortedByDayAlias.
@Test
public void testMultipleTimeGrainsSortedByDayAlias() throws Exception {
Map<String, Argument> dayArguments = new HashMap<>();
dayArguments.put("grain", Argument.builder().name("grain").value(TimeGrain.DAY).build());
Map<String, Argument> monthArguments = new HashMap<>();
monthArguments.put("grain", Argument.builder().name("grain").value(TimeGrain.MONTH).build());
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("byDay", Sorting.SortOrder.asc);
Set<Attribute> sortAttributes = new HashSet<>(Arrays.asList(Attribute.builder().type(TIME_TYPE).name("recordedDate").alias("byDay").arguments(dayArguments.values()).build()));
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byDay", dayArguments)).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byMonth", monthArguments)).sorting(new SortingImpl(sortMap, ClassType.of(PlayerStats.class), sortAttributes, dictionary)).build();
List<PlayerStats> results = toList(engine.executeQuery(query, transaction).getData());
assertEquals(3, results.size());
assertEquals(2412, results.get(0).getHighScore());
assertEquals(new Day(Date.valueOf("2019-07-11")), results.get(0).fetch("byDay", null));
assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(0).fetch("byMonth", null));
assertEquals(1234, results.get(1).getHighScore());
assertEquals(new Day(Date.valueOf("2019-07-12")), results.get(1).fetch("byDay", null));
assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(1).fetch("byMonth", null));
assertEquals(1000, results.get(2).getHighScore());
assertEquals(new Day(Date.valueOf("2019-07-13")), results.get(2).fetch("byDay", null));
assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(2).fetch("byMonth", null));
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class CurrencyRate method testLogicalReference.
@Test
public void testLogicalReference() {
Map<String, Argument> impressionsArg = new HashMap<>();
impressionsArg.put("aggregation", Argument.builder().name("aggregation").value("SUM").build());
SQLMetricProjection impressions = (SQLMetricProjection) revenueFactTable.getMetricProjection("impressions", "impressions", impressionsArg);
Map<String, Argument> testImpressionsArg = new HashMap<>();
testImpressionsArg.put("aggregation", Argument.builder().name("aggregation").value("MIN").build());
SQLMetricProjection testImpressions = (SQLMetricProjection) revenueFactTable.getMetricProjection("testImpressions", "testImpressions", testImpressionsArg);
SQLMetricProjection testRevenue = (SQLMetricProjection) revenueFactTable.getMetricProjection("testRevenue");
SQLMetricProjection testRevenueLogicalRef = (SQLMetricProjection) revenueFactTable.getMetricProjection("testRevenueLogicalRef");
Map<String, Argument> revenueArg = new HashMap<>();
revenueArg.put("format", Argument.builder().name("format").value("11D00").build());
SQLMetricProjection revenueWithArg = (SQLMetricProjection) revenueFactTable.getMetricProjection("revenue", "revenueWithArg", revenueArg);
SQLDimensionProjection conversionRate = (SQLDimensionProjection) revenueFactTable.getDimensionProjection("conversionRate");
SQLDimensionProjection rateProvider = (SQLDimensionProjection) revenueFactTable.getDimensionProjection("rateProvider");
Query query = Query.builder().source(revenueFactTable).metricProjection(impressions).metricProjection(testImpressions).metricProjection(testRevenue).metricProjection(testRevenueLogicalRef).metricProjection(revenueWithArg).dimensionProjection(conversionRate).dimensionProjection(rateProvider).arguments(queryArgs).build();
Query.QueryBuilder builder = Query.builder().source(query.getSource()).metricProjections(query.getMetricProjections()).dimensionProjections(query.getDimensionProjections()).arguments(query.getArguments());
Query expandedQuery = addHiddenProjections(metaDataStore, builder, query).build();
// definition: {{$$column.args.aggregation}}({{$impressions}})
// -> value of 'aggregation' argument is passed in the query for "impressions" column and same is used while
// resolving this column.
assertEquals("SUM(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`impressions`)", impressions.toSQL(expandedQuery, metaDataStore));
// definition: {{impressions}}) * {{$$table.args.testPercentage}}
// -> default value of table argument 'testPercentage' is used.
// -> value of 'aggregation' argument is passed in the query for "testImpressions" column and same is used while
// resolving referenced column "impressions".
assertEquals("MIN(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`impressions`)) * 0.1", testImpressions.toSQL(expandedQuery, metaDataStore));
// definition: {{revenue}}
// revenue definition: TO_CHAR(SUM({{$revenue}}) * {{rate.conversionRate}}, {{$$column.args.format}})
// -> default value of 'format' argument in "revenue" column is used while resolving this column.
// -> default 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`.`revenue`)" + " * TO_CHAR(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`conversion_rate`, 99D00), 99D00)", testRevenue.toSQL(expandedQuery, metaDataStore));
// definition: {{revenueUsingLogicalRef}}
// revenueUsingLogicalRef's definition: TO_CHAR(SUM({{$revenue}}) * {{conversionRate}}, {{$$column.args.format}})
// -> default value of 'format' argument in "revenueUsingLogicalRef" column is used while resolving this column.
// -> This column references "conversionRate" which references "rate.conversionRate". Since conversionRate doesn't have
// 'format' argument defined, default value of 'format' argument in joined table's "conversionRate" column is used.
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`, 9D0), 99D00)", testRevenueLogicalRef.toSQL(expandedQuery, metaDataStore));
// definition: TO_CHAR(SUM({{$revenue}}) * {{rate.conversionRate}}, {{$$column.args.format}})
// -> value of 'format' argument is passed in the query for "revenue" column and same is used for resolving
// referenced column "rate.conversionRate" and this column.
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`, 11D00), 11D00)", revenueWithArg.toSQL(expandedQuery, metaDataStore));
// definition: {{rate.conversionRate}}
// -> logical column 'conversionRate' doesn't support arguments.
// -> default value of 'format' argument in "conversionRate" column of joined table is used while resolving this.
assertEquals("TO_CHAR(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`conversion_rate`, 9D0)", conversionRate.toSQL(expandedQuery, metaDataStore));
// definition: {{rate.$provider}}
assertEquals("`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`provider`", rateProvider.toSQL(expandedQuery, metaDataStore));
}
use of com.yahoo.elide.core.request.Argument 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));
}
Aggregations