Search in sources :

Example 31 with SortingImpl

use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.

the class AggregateBeforeJoinOptimizerTest method testSortOnDimensionInProjectionRequiringJoin.

@Test
public void testSortOnDimensionInProjectionRequiringJoin() {
    SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
    Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
    sortMap.put("countryIsoCode", Sorting.SortOrder.desc);
    Query query = Query.builder().source(gameRevenueTable).dimensionProjection(gameRevenueTable.getDimensionProjection("countryIsoCode")).metricProjection(gameRevenueTable.getMetricProjection("revenue")).sorting(new SortingImpl(sortMap, GameRevenue.class, dictionary)).build();
    String expected = "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` " + "ORDER BY `example_GameRevenue_XXX_country_XXX`.`iso_code` DESC\n";
    compareQueryLists(expected, engine.explain(query));
    testQueryExecution(query);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) TreeMap(java.util.TreeMap) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 32 with SortingImpl

use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.

the class QueryEngineTest method testMultipleTimeGrains.

@Test
public void testMultipleTimeGrains() 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);
    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, PlayerStats.class, dictionary)).build();
    List<PlayerStats> results = toList(engine.executeQuery(query, transaction).getData());
    assertEquals(3, results.size());
    assertEquals(1000, results.get(0).getHighScore());
    assertEquals(new Day(Date.valueOf("2019-07-13")), 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(2412, results.get(2).getHighScore());
    assertEquals(new Day(Date.valueOf("2019-07-11")), results.get(2).fetch("byDay", null));
    assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(2).fetch("byMonth", null));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) PlayerStats(example.PlayerStats) TreeMap(java.util.TreeMap) Month(com.yahoo.elide.datastores.aggregation.timegrains.Month) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) Day(com.yahoo.elide.datastores.aggregation.timegrains.Day) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 33 with SortingImpl

use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.

the class AggregateBeforeJoinOptimizerTest method testSortingOnMetricInProjection.

@Test
public void testSortingOnMetricInProjection() {
    SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
    Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
    sortMap.put("revenue", Sorting.SortOrder.desc);
    Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).dimensionProjection(gameRevenueTable.getDimensionProjection("countryIsoCode")).sorting(new SortingImpl(sortMap, GameRevenue.class, dictionary)).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` " + "ORDER BY MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) DESC\n", engine.explain(query));
    testQueryExecution(query);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) TreeMap(java.util.TreeMap) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 34 with SortingImpl

use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.

the class AggregateBeforeJoinOptimizerTest method testSortOnTimeDimensionInProjectionNotRequiringJoin.

@Test
public void testSortOnTimeDimensionInProjectionNotRequiringJoin() {
    SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
    Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
    sortMap.put("saleDate", Sorting.SortOrder.desc);
    Query query = Query.builder().source(gameRevenueTable).dimensionProjection(gameRevenueTable.getDimensionProjection("countryIsoCode")).timeDimensionProjection(gameRevenueTable.getTimeDimensionProjection("saleDate")).metricProjection(gameRevenueTable.getMetricProjection("revenue")).sorting(new SortingImpl(sortMap, GameRevenue.class, dictionary)).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` " + "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` " + "ORDER BY `example_GameRevenue_XXX`.`saleDate` DESC\n";
    compareQueryLists(expected, engine.explain(query));
    testQueryExecution(query);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) TreeMap(java.util.TreeMap) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 35 with SortingImpl

use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.

the class AggregateBeforeJoinOptimizerTest method testSortOnMultiReferenceDimensionInProjection.

@Test
public void testSortOnMultiReferenceDimensionInProjection() {
    SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
    Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
    sortMap.put("countryCategory", Sorting.SortOrder.desc);
    Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).dimensionProjection(gameRevenueTable.getDimensionProjection("countryCategory")).sorting(new SortingImpl(sortMap, GameRevenue.class, dictionary)).build();
    String expected = "SELECT MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) AS `revenue`," + "CASE WHEN `example_GameRevenue_XXX_country_XXX`.`iso_code` = 'US' THEN `example_GameRevenue_XXX`.`category` ELSE 'UNKNONWN' END AS `countryCategory` " + "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` " + "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 CASE WHEN `example_GameRevenue_XXX_country_XXX`.`iso_code` = 'US' THEN `example_GameRevenue_XXX`.`category` ELSE 'UNKNONWN' END " + "ORDER BY CASE WHEN `example_GameRevenue_XXX_country_XXX`.`iso_code` = 'US' THEN `example_GameRevenue_XXX`.`category` ELSE 'UNKNONWN' END DESC\n";
    compareQueryLists(expected, engine.explain(query));
    testQueryExecution(query);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) TreeMap(java.util.TreeMap) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

SortingImpl (com.yahoo.elide.core.sort.SortingImpl)53 Test (org.junit.jupiter.api.Test)53 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)29 Query (com.yahoo.elide.datastores.aggregation.query.Query)29 TreeMap (java.util.TreeMap)29 HashMap (java.util.HashMap)23 EntityProjection (com.yahoo.elide.core.request.EntityProjection)15 Book (example.Book)15 PlayerStats (example.PlayerStats)12 Sorting (com.yahoo.elide.core.request.Sorting)10 Path (com.yahoo.elide.core.Path)9 Relationship (com.yahoo.elide.core.request.Relationship)8 Author (example.Author)8 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)7 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)7 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)7 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)6 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)6 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)6 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)6