Search in sources :

Example 31 with Query

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);
}
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 32 with Query

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);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) PlayerStats(example.PlayerStats) 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 Query

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");
}
Also used : QueryResult(com.yahoo.elide.datastores.aggregation.query.QueryResult) Query(com.yahoo.elide.datastores.aggregation.query.Query) ImmutablePagination(com.yahoo.elide.datastores.aggregation.query.ImmutablePagination) PlayerStats(example.PlayerStats) Day(com.yahoo.elide.datastores.aggregation.timegrains.Day) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 34 with Query

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);
}
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 35 with Query

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);
}
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)

Aggregations

Query (com.yahoo.elide.datastores.aggregation.query.Query)242 Test (org.junit.jupiter.api.Test)229 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)214 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)51 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)46 Argument (com.yahoo.elide.core.request.Argument)43 ArrayList (java.util.ArrayList)42 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)37 Path (com.yahoo.elide.core.Path)35 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)31 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)29 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)29 PlayerStats (example.PlayerStats)29 TreeMap (java.util.TreeMap)29 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)28 HashMap (java.util.HashMap)26 Date (java.util.Date)19 HashSet (java.util.HashSet)17 ToString (lombok.ToString)16 SQLDimensionProjection (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection)14