use of com.yahoo.elide.core.sort.SortingImpl 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.core.sort.SortingImpl 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.core.sort.SortingImpl 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);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class QueryEngineTest method testSortAggregatedMetric.
@Test
public void testSortAggregatedMetric() throws Exception {
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("lowScore", Sorting.SortOrder.desc);
Query query = Query.builder().source(playerStatsTable).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).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(241);
stats0.setOverallRating("Great");
PlayerStats stats1 = new PlayerStats();
stats1.setId("1");
stats1.setLowScore(35);
stats1.setOverallRating("Good");
assertEquals(ImmutableList.of(stats0, stats1), results);
}
use of com.yahoo.elide.core.sort.SortingImpl 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