Search in sources :

Example 6 with SortingImpl

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);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) PlayerStats(example.PlayerStats) TreeMap(java.util.TreeMap) Day(com.yahoo.elide.datastores.aggregation.timegrains.Day) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 7 with SortingImpl

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);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) PlayerStats(example.PlayerStats) TreeMap(java.util.TreeMap) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 8 with SortingImpl

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);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) PlayerStats(example.PlayerStats) TreeMap(java.util.TreeMap) Day(com.yahoo.elide.datastores.aggregation.timegrains.Day) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 9 with SortingImpl

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);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) PlayerStats(example.PlayerStats) TreeMap(java.util.TreeMap) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 10 with SortingImpl

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));
}
Also used : Path(com.yahoo.elide.core.Path) 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) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Day(com.yahoo.elide.datastores.aggregation.timegrains.Day) HashSet(java.util.HashSet) 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