use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class QueryEngineTest method testSortByMultipleColumns.
/**
* Test sorting by two different columns-one metric and one dimension.
*
* @throws Exception exception
*/
@Test
public void testSortByMultipleColumns() throws Exception {
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("lowScore", Sorting.SortOrder.desc);
sortMap.put("playerName", Sorting.SortOrder.asc);
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("lowScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate")).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).build();
List<Object> results = toList(engine.executeQuery(query, transaction).getData());
PlayerStats stats0 = new PlayerStats();
stats0.setId("0");
stats0.setLowScore(241);
stats0.setOverallRating("Great");
stats0.setRecordedDate(new Day(Date.valueOf("2019-07-11")));
PlayerStats stats1 = new PlayerStats();
stats1.setId("1");
stats1.setLowScore(72);
stats1.setOverallRating("Good");
stats1.setRecordedDate(new Day(Date.valueOf("2019-07-13")));
PlayerStats stats2 = new PlayerStats();
stats2.setId("2");
stats2.setLowScore(35);
stats2.setOverallRating("Good");
stats2.setRecordedDate(new Day(Date.valueOf("2019-07-12")));
assertEquals(ImmutableList.of(stats0, stats1, stats2), results);
}
use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class QueryEngineTest method testTotalScoreByMonth.
/**
* Test month grain query.
*
* @throws Exception exception
*/
@Test
public void testTotalScoreByMonth() throws Exception {
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate")).build();
// Change for monthly column
List<Object> results = toList(engine.executeQuery(query, transaction).getData());
PlayerStats stats0 = new PlayerStats();
stats0.setId("0");
stats0.setHighScore(2412);
stats0.setRecordedDate(new Day(Date.valueOf("2019-07-11")));
PlayerStats stats1 = new PlayerStats();
stats1.setId("1");
stats1.setHighScore(1234);
stats1.setRecordedDate(new Day(Date.valueOf("2019-07-12")));
PlayerStats stats2 = new PlayerStats();
stats2.setId("2");
stats2.setHighScore(1000);
stats2.setRecordedDate(new Day(Date.valueOf("2019-07-13")));
assertEquals(ImmutableList.of(stats0, stats1, stats2), results);
}
use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class QueryEngineTest method testPaginationWithFilter.
/**
* Nested Queries with filter - Pagination
* @throws Exception
*/
@Test
public void testPaginationWithFilter() throws Exception {
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("dailyAverageScorePerPeriod")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).whereFilter(filterParser.parseFilterExpression("overallRating==Great", playerStatsType, false)).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate")).pagination(new ImmutablePagination(0, 1, false, true)).build();
QueryResult result = engine.executeQuery(query, transaction);
List<Object> data = toList(result.getData());
// Jon Doe,1234,72,Good,840,2019-07-12 00:00:00
PlayerStats stats1 = new PlayerStats();
stats1.setId("0");
stats1.setDailyAverageScorePerPeriod(2412.0f);
stats1.setOverallRating("Great");
stats1.setRecordedDate(new Day(Date.valueOf("2019-07-11")));
assertEquals(ImmutableList.of(stats1), data, "Returned record does not match");
assertEquals(1, result.getPageTotals(), "Page totals does not match");
}
use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class QueryEngineTest method testAmbiguousFields.
@Test
public void testAmbiguousFields() throws Exception {
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("lowScore", Sorting.SortOrder.asc);
Query query = Query.builder().source(playerStatsTable).dimensionProjection(playerStatsTable.getDimensionProjection("playerName")).dimensionProjection(playerStatsTable.getDimensionProjection("player2Name")).metricProjection(playerStatsTable.getMetricProjection("lowScore")).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).build();
List<Object> results = toList(engine.executeQuery(query, transaction).getData());
PlayerStats stats0 = new PlayerStats();
stats0.setId("0");
stats0.setLowScore(35);
stats0.setPlayerName("Jon Doe");
stats0.setPlayer2Name("Jane Doe");
PlayerStats stats1 = new PlayerStats();
stats1.setId("1");
stats1.setLowScore(72);
stats1.setPlayerName("Han");
stats1.setPlayer2Name("Jon Doe");
PlayerStats stats2 = new PlayerStats();
stats2.setId("2");
stats2.setLowScore(241);
stats2.setPlayerName("Jane Doe");
stats2.setPlayer2Name("Han");
assertEquals(ImmutableList.of(stats0, stats1, stats2), results);
}
use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class QueryEngineTest method testSortJoin.
/**
* Test sorting by dimension attribute which is not present in the query.
*
* @throws Exception exception
*/
@Test
public void testSortJoin() throws Exception {
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("playerName", Sorting.SortOrder.asc);
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("lowScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate")).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).build();
List<Object> results = toList(engine.executeQuery(query, transaction).getData());
PlayerStats stats0 = new PlayerStats();
stats0.setId("0");
stats0.setLowScore(72);
stats0.setOverallRating("Good");
stats0.setRecordedDate(new Day(Date.valueOf("2019-07-13")));
PlayerStats stats1 = new PlayerStats();
stats1.setId("1");
stats1.setLowScore(241);
stats1.setOverallRating("Great");
stats1.setRecordedDate(new Day(Date.valueOf("2019-07-11")));
PlayerStats stats2 = new PlayerStats();
stats2.setId("2");
stats2.setLowScore(35);
stats2.setOverallRating("Good");
stats2.setRecordedDate(new Day(Date.valueOf("2019-07-12")));
assertEquals(ImmutableList.of(stats0, stats1, stats2), results);
}
Aggregations