use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class InMemoryStoreTransactionTest method testSortOnComplexAttribute.
@Test
public void testSortOnComplexAttribute() {
Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
sortOrder.put("homeAddress.street1", Sorting.SortOrder.asc);
Sorting sorting = new SortingImpl(sortOrder, Author.class, dictionary);
EntityProjection projection = EntityProjection.builder().type(Author.class).sorting(sorting).build();
DataStoreIterable sortInMemory = new DataStoreIterableBuilder(Arrays.asList(author1, author2)).sortInMemory(true).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(sortInMemory);
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
assertEquals(2, loaded.size());
Object[] sorted = loaded.toArray();
assertEquals(author2, sorted[0]);
assertEquals(author1, sorted[1]);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class InMemoryStoreTransactionTest method testSortingRequiresInMemoryPagination.
@Test
public void testSortingRequiresInMemoryPagination() {
PaginationImpl pagination = new PaginationImpl(ClassType.of(Book.class), 0, 3, 10, 10, true, false);
Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
sortOrder.put("title", Sorting.SortOrder.desc);
Sorting sorting = new SortingImpl(sortOrder, Book.class, dictionary);
EntityProjection projection = EntityProjection.builder().type(Book.class).sorting(sorting).pagination(pagination).build();
DataStoreIterable sortInMemory = new DataStoreIterableBuilder(books).sortInMemory(true).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(sortInMemory);
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
verify(wrappedTransaction, times(1)).loadObjects(any(EntityProjection.class), eq(scope));
assertEquals(3, loaded.size());
List<String> bookTitles = loaded.stream().map((o) -> ((Book) o).getTitle()).collect(Collectors.toList());
assertEquals(Lists.newArrayList("Book 3", "Book 2", "Book 1"), bookTitles);
assertEquals(3, pagination.getPageTotals());
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testSortAndPaginate.
@Test
public void testSortAndPaginate() {
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("highScore", Sorting.SortOrder.desc);
// WHERE filter
FilterPredicate predicate = new FilterPredicate(new Path(PlayerStats.class, dictionary, "highScore"), Operator.GT, Arrays.asList(9000));
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate")).pagination(new ImmutablePagination(10, 5, false, true)).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).havingFilter(predicate).whereFilter(parseFilterExpression("countryIsoCode==USA", playerStatsType, false)).build();
String expectedQueryStr1 = "SELECT COUNT(*) FROM " + "(SELECT `example_PlayerStats_XXX`.`overallRating`, " + "`example_PlayerStats_XXX`.`recordedDate` " + "FROM (SELECT MAX(`example_PlayerStats`.`highScore`) AS `INNER_AGG_XXX`," + "`example_PlayerStats`.`overallRating` AS `overallRating`," + "`example_PlayerStats`.`country_id` AS `country_id`," + "PARSEDATETIME(FORMATDATETIME(`example_PlayerStats`.`recordedDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') AS `recordedDate` " + "FROM `playerStats` AS `example_PlayerStats` " + "GROUP BY `example_PlayerStats`.`overallRating`, " + "`example_PlayerStats`.`country_id`, " + "PARSEDATETIME(FORMATDATETIME(`example_PlayerStats`.`recordedDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') ) " + "AS `example_PlayerStats_XXX` " + "LEFT OUTER JOIN `countries` AS `example_PlayerStats_XXX_country_XXX` " + "ON `example_PlayerStats_XXX`.`country_id` = `example_PlayerStats_XXX_country_XXX`.`id` " + "WHERE `example_PlayerStats_XXX_country_XXX`.`iso_code` IN (:XXX) " + "GROUP BY `example_PlayerStats_XXX`.`overallRating`, " + "`example_PlayerStats_XXX`.`recordedDate` " + "HAVING MAX(`example_PlayerStats_XXX`.`INNER_AGG_XXX`) > :XXX ) AS `pagination_subquery`\n";
String expectedQueryStr2 = "SELECT MAX(`example_PlayerStats_XXX`.`INNER_AGG_XXX`) AS `highScore`," + "`example_PlayerStats_XXX`.`overallRating` AS `overallRating`," + "`example_PlayerStats_XXX`.`recordedDate` AS `recordedDate` " + "FROM (SELECT MAX(`example_PlayerStats`.`highScore`) AS `INNER_AGG_XXX`," + "`example_PlayerStats`.`overallRating` AS `overallRating`," + "`example_PlayerStats`.`country_id` AS `country_id`," + "PARSEDATETIME(FORMATDATETIME(`example_PlayerStats`.`recordedDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') AS `recordedDate` " + "FROM `playerStats` AS `example_PlayerStats` " + "GROUP BY `example_PlayerStats`.`overallRating`, " + "`example_PlayerStats`.`country_id`, " + "PARSEDATETIME(FORMATDATETIME(`example_PlayerStats`.`recordedDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') ) " + "AS `example_PlayerStats_XXX` " + "LEFT OUTER JOIN `countries` AS `example_PlayerStats_XXX_country_XXX` " + "ON `example_PlayerStats_XXX`.`country_id` = `example_PlayerStats_XXX_country_XXX`.`id` " + "WHERE `example_PlayerStats_XXX_country_XXX`.`iso_code` IN (:XXX) " + "GROUP BY `example_PlayerStats_XXX`.`overallRating`, " + "`example_PlayerStats_XXX`.`recordedDate` " + "HAVING MAX(`example_PlayerStats_XXX`.`INNER_AGG_XXX`) > :XXX " + "ORDER BY MAX(`example_PlayerStats_XXX`.`INNER_AGG_XXX`) " + "DESC LIMIT 5 OFFSET 10\n";
List<String> expectedQueryList = new ArrayList<>();
expectedQueryList.add(expectedQueryStr1);
expectedQueryList.add(expectedQueryStr2);
compareQueryLists(expectedQueryList, engine.explain(query));
testQueryExecution(query);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testSortOnMultiReferenceTimeDimensionInProjection.
@Test
public void testSortOnMultiReferenceTimeDimensionInProjection() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("lastDate", Sorting.SortOrder.desc);
Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).timeDimensionProjection(gameRevenueTable.getTimeDimensionProjection("lastDate")).sorting(new SortingImpl(sortMap, GameRevenue.class, dictionary)).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') " + "ORDER 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') DESC\n";
compareQueryLists(expected, engine.explain(query));
testQueryExecution(query);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testSortOnDimensionInProjectionNotRequiringJoin.
@Test
public void testSortOnDimensionInProjectionNotRequiringJoin() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("category", Sorting.SortOrder.desc);
Query query = Query.builder().source(gameRevenueTable).dimensionProjection(gameRevenueTable.getDimensionProjection("countryIsoCode")).dimensionProjection(gameRevenueTable.getDimensionProjection("category")).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`.`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` " + "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` " + "ORDER BY `example_GameRevenue_XXX`.`category` DESC\n";
compareQueryLists(expected, engine.explain(query));
testQueryExecution(query);
}
Aggregations