use of com.yahoo.elide.datastores.aggregation.timegrains.Month 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));
}
use of com.yahoo.elide.datastores.aggregation.timegrains.Month in project elide by yahoo.
the class QueryEngineTest method testMultipleTimeGrainsSortedByDayAlias.
@Test
public void testMultipleTimeGrainsSortedByDayAlias() 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("byDay", Sorting.SortOrder.asc);
Set<Attribute> sortAttributes = new HashSet<>(Arrays.asList(Attribute.builder().type(TIME_TYPE).name("recordedDate").alias("byDay").arguments(dayArguments.values()).build()));
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byDay", dayArguments)).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byMonth", monthArguments)).sorting(new SortingImpl(sortMap, ClassType.of(PlayerStats.class), sortAttributes, dictionary)).build();
List<PlayerStats> results = toList(engine.executeQuery(query, transaction).getData());
assertEquals(3, 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));
assertEquals(1234, results.get(1).getHighScore());
assertEquals(new Day(Date.valueOf("2019-07-12")), results.get(1).fetch("byDay", null));
assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(1).fetch("byMonth", null));
assertEquals(1000, results.get(2).getHighScore());
assertEquals(new Day(Date.valueOf("2019-07-13")), results.get(2).fetch("byDay", null));
assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(2).fetch("byMonth", null));
}
use of com.yahoo.elide.datastores.aggregation.timegrains.Month in project elide by yahoo.
the class MonthSerdeTest method testDateDeserialize.
@Test
public void testDateDeserialize() {
LocalDateTime localDate = LocalDateTime.of(2020, java.time.Month.of(01), 01, 00, 00, 00);
Month expectedDate = new Month(localDate);
Serde serde = new Month.MonthSerde();
Object actualDate = serde.deserialize("2020-01");
assertEquals(expectedDate, actualDate);
}
use of com.yahoo.elide.datastores.aggregation.timegrains.Month in project elide by yahoo.
the class QueryEngineTest method testMetricFormulaWithQueryPlan.
@Test
public void testMetricFormulaWithQueryPlan() throws Exception {
Map<String, Argument> arguments = new HashMap<>();
arguments.put("grain", Argument.builder().name("grain").value(TimeGrain.MONTH).build());
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("dailyAverageScorePerPeriod")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", arguments)).build();
List<Object> results = toList(engine.executeQuery(query, transaction).getData());
PlayerStats stats0 = new PlayerStats();
stats0.setId("0");
stats0.setDailyAverageScorePerPeriod((float) 1548.6666);
stats0.setRecordedDate(new Month(Date.valueOf("2019-07-01")));
assertEquals(ImmutableList.of(stats0), results);
}
use of com.yahoo.elide.datastores.aggregation.timegrains.Month in project elide by yahoo.
the class QueryEngineTest method testMultipleTimeGrains.
@Test
public void testMultipleTimeGrains() 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);
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).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(3, results.size());
assertEquals(1000, results.get(0).getHighScore());
assertEquals(new Day(Date.valueOf("2019-07-13")), results.get(0).fetch("byDay", null));
assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(0).fetch("byMonth", null));
assertEquals(1234, results.get(1).getHighScore());
assertEquals(new Day(Date.valueOf("2019-07-12")), results.get(1).fetch("byDay", null));
assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(1).fetch("byMonth", null));
assertEquals(2412, results.get(2).getHighScore());
assertEquals(new Day(Date.valueOf("2019-07-11")), results.get(2).fetch("byDay", null));
assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(2).fetch("byMonth", null));
}
Aggregations