Search in sources :

Example 36 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.

the class QueryEngineTest method testDegenerateDimensionFilter.

/**
 * Test group by a degenerate dimension with a filter applied.
 *
 * @throws Exception exception
 */
@Test
public void testDegenerateDimensionFilter() throws Exception {
    Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("lowScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate")).whereFilter(filterParser.parseFilterExpression("overallRating==Great", playerStatsType, false)).build();
    List<Object> results = toList(engine.executeQuery(query, transaction).getData());
    PlayerStats stats1 = new PlayerStats();
    stats1.setId("0");
    stats1.setLowScore(241);
    stats1.setOverallRating("Great");
    stats1.setRecordedDate(new Day(Date.valueOf("2019-07-11")));
    assertEquals(ImmutableList.of(stats1), 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 37 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query 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 38 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.

the class QueryEngineTest method testNullJoinToStringValue.

@Test
public void testNullJoinToStringValue() throws Exception {
    Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).dimensionProjection(playerStatsTable.getDimensionProjection("countryNickName")).build();
    List<Object> results = toList(engine.executeQuery(query, transaction).getData());
    PlayerStats stats1 = new PlayerStats();
    stats1.setId("1");
    stats1.setHighScore(2412);
    stats1.setCountryNickName("Uncle Sam");
    PlayerStats stats2 = new PlayerStats();
    stats2.setId("0");
    stats2.setHighScore(1000);
    stats2.setCountryNickName(null);
    assertEquals(ImmutableList.of(stats2, stats1), results);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) PlayerStats(example.PlayerStats) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 39 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.

the class QueryEngineTest method testHavingClause.

/**
 * Test having clause integrates with group by clause.
 *
 * @throws Exception exception
 */
@Test
public void testHavingClause() throws Exception {
    Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).havingFilter(filterParser.parseFilterExpression("highScore < 2400", playerStatsType, false)).build();
    List<Object> results = toList(engine.executeQuery(query, transaction).getData());
    // Only "Good" rating would have total high score less than 2400
    PlayerStats stats1 = new PlayerStats();
    stats1.setId("0");
    stats1.setOverallRating("Good");
    stats1.setHighScore(1234);
    assertEquals(ImmutableList.of(stats1), results);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) PlayerStats(example.PlayerStats) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 40 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.

the class QueryEngineTest method testJoinToGroupBy.

/**
 * Test grouping by a dimension with a JoinTo annotation.
 *
 * @throws Exception exception
 */
@Test
public void testJoinToGroupBy() throws Exception {
    Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).dimensionProjection(playerStatsTable.getDimensionProjection("countryIsoCode")).build();
    List<Object> results = toList(engine.executeQuery(query, transaction).getData());
    PlayerStats stats1 = new PlayerStats();
    stats1.setId("1");
    stats1.setHighScore(2412);
    stats1.setCountryIsoCode("USA");
    PlayerStats stats2 = new PlayerStats();
    stats2.setId("0");
    stats2.setHighScore(1000);
    stats2.setCountryIsoCode("HKG");
    assertEquals(ImmutableList.of(stats2, stats1), results);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) PlayerStats(example.PlayerStats) 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