use of com.yahoo.elide.core.Path in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testHavingOnMetricInProjection.
@Test
public void testHavingOnMetricInProjection() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
FilterPredicate predicate = new FilterPredicate(new Path(GameRevenue.class, dictionary, "revenue"), Operator.GT, Arrays.asList(9000));
Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).dimensionProjection(gameRevenueTable.getDimensionProjection("countryIsoCode")).havingFilter(predicate).build();
compareQueryLists("SELECT MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) AS `revenue`," + "`example_GameRevenue_XXX_country_XXX`.`iso_code` AS `countryIsoCode` " + "FROM (SELECT MAX(`example_GameRevenue`.`revenue`) AS `INNER_AGG_XXX`," + "`example_GameRevenue`.`country_id` AS `country_id` FROM `gameRevenue` AS `example_GameRevenue` " + "GROUP BY `example_GameRevenue`.`country_id` ) 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` " + "HAVING MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) > :XXX\n", engine.explain(query));
testQueryExecution(query);
}
use of com.yahoo.elide.core.Path in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testHavingOnTimeDimensionInProjectionRequiringJoin.
@Test
public void testHavingOnTimeDimensionInProjectionRequiringJoin() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
FilterExpression expression = new OrFilterExpression(new FilterPredicate(new Path(GameRevenue.class, dictionary, "revenue"), Operator.GT, Arrays.asList(9000)), new FilterPredicate(new Path(GameRevenue.class, dictionary, "sessionDate"), Operator.IN, Arrays.asList(new Day(new Date()))));
Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).timeDimensionProjection(gameRevenueTable.getTimeDimensionProjection("sessionDate")).havingFilter(expression).build();
compareQueryLists("SELECT MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) AS `revenue`," + "PARSEDATETIME(FORMATDATETIME(`example_GameRevenue_XXX_playerStats_XXX`.`recordedDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') AS `sessionDate` " + "FROM (SELECT MAX(`example_GameRevenue`.`revenue`) AS `INNER_AGG_XXX`," + "`example_GameRevenue`.`player_stats_id` AS `player_stats_id` " + "FROM `gameRevenue` AS `example_GameRevenue` " + "GROUP BY `example_GameRevenue`.`player_stats_id` ) " + "AS `example_GameRevenue_XXX` " + "LEFT OUTER JOIN `playerStats` AS `example_GameRevenue_XXX_playerStats_XXX` " + "ON `example_GameRevenue_XXX`.`player_stats_id` = `example_GameRevenue_XXX_playerStats_XXX`.`id` " + "GROUP BY PARSEDATETIME(FORMATDATETIME(`example_GameRevenue_XXX_playerStats_XXX`.`recordedDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') " + "HAVING (MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) > :XXX " + "OR PARSEDATETIME(FORMATDATETIME(`example_GameRevenue_XXX_playerStats_XXX`.`recordedDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') IN (:XXX))\n", engine.explain(query));
testQueryExecution(query);
}
use of com.yahoo.elide.core.Path in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testWhereOnTimeDimensionNotInProjectionNotRequiringJoin.
@Test
public void testWhereOnTimeDimensionNotInProjectionNotRequiringJoin() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
FilterExpression where = new AndFilterExpression(new FilterPredicate(new Path(GameRevenue.class, dictionary, "countryIsoCode"), Operator.IN, Arrays.asList("foo")), new FilterPredicate(new Path(GameRevenue.class, dictionary, "saleDate"), Operator.IN, Arrays.asList(new Day(new Date()))));
Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).whereFilter(where).build();
String expected = "SELECT MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) AS `revenue` " + "FROM (SELECT MAX(`example_GameRevenue`.`revenue`) AS `INNER_AGG_XXX`," + "`example_GameRevenue`.`country_id` AS `country_id` " + "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` ) " + "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` " + "WHERE `example_GameRevenue_XXX_country_XXX`.`iso_code` IN (:XXX)\n";
compareQueryLists(expected, engine.explain(query));
testQueryExecution(query);
}
use of com.yahoo.elide.core.Path in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testHavingOnMultiReferenceTimeDimensionInProjection.
@Test
public void testHavingOnMultiReferenceTimeDimensionInProjection() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
FilterExpression having = new OrFilterExpression(new FilterPredicate(new Path(GameRevenue.class, dictionary, "revenue"), Operator.GT, Arrays.asList(100)), new FilterPredicate(new Path(GameRevenue.class, dictionary, "lastDate"), Operator.IN, Arrays.asList(new Day(new Date()))));
Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).timeDimensionProjection(gameRevenueTable.getTimeDimensionProjection("lastDate")).havingFilter(having).build();
String expected = "SELECT MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) AS `revenue`," + "PARSEDATETIME(FORMATDATETIME(CASE WHEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` > `example_GameRevenue_XXX`.`saleDate` THEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` ELSE `example_GameRevenue_XXX`.`saleDate` END, 'yyyy-MM-dd'), 'yyyy-MM-dd') AS `lastDate` " + "FROM (SELECT MAX(`example_GameRevenue`.`revenue`) AS `INNER_AGG_XXX`," + "`example_GameRevenue`.`player_stats_id` AS `player_stats_id`," + "`example_GameRevenue`.`saleDate` AS `saleDate` " + "FROM `gameRevenue` AS `example_GameRevenue` " + "GROUP BY `example_GameRevenue`.`player_stats_id`, " + "`example_GameRevenue`.`saleDate` ) " + "AS `example_GameRevenue_XXX` " + "LEFT OUTER JOIN `playerStats` AS `example_GameRevenue_XXX_playerStats_XXX` " + "ON `example_GameRevenue_XXX`.`player_stats_id` = `example_GameRevenue_XXX_playerStats_XXX`.`id` " + "GROUP BY PARSEDATETIME(FORMATDATETIME(CASE WHEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` > `example_GameRevenue_XXX`.`saleDate` THEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` ELSE `example_GameRevenue_XXX`.`saleDate` END, 'yyyy-MM-dd'), 'yyyy-MM-dd') " + "HAVING (MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) > :XXX " + "OR PARSEDATETIME(FORMATDATETIME(CASE WHEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` > `example_GameRevenue_XXX`.`saleDate` THEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` ELSE `example_GameRevenue_XXX`.`saleDate` END, 'yyyy-MM-dd'), 'yyyy-MM-dd') IN (:XXX))\n";
compareQueryLists(expected, engine.explain(query));
testQueryExecution(query);
}
use of com.yahoo.elide.core.Path in project elide by yahoo.
the class QueryEngineTest method testMultipleTimeGrainsFilteredByDayAlias.
@Test
public void testMultipleTimeGrainsFilteredByDayAlias() 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("highScore", Sorting.SortOrder.asc);
FilterPredicate predicate = new FilterPredicate(new Path(ClassType.of(PlayerStats.class), dictionary, "recordedDate", "byDay", new HashSet<>(dayArguments.values())), Operator.IN, Lists.newArrayList(new Day(Date.valueOf("2019-07-11"))));
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).whereFilter(predicate).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byDay", dayArguments)).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byMonth", monthArguments)).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).build();
List<PlayerStats> results = toList(engine.executeQuery(query, transaction).getData());
assertEquals(1, 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));
}
Aggregations