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