Search in sources :

Example 1 with Month

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

Example 2 with Month

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));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) Attribute(com.yahoo.elide.core.request.Attribute) PlayerStats(example.PlayerStats) TreeMap(java.util.TreeMap) Month(com.yahoo.elide.datastores.aggregation.timegrains.Month) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) 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)

Example 3 with Month

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Month(com.yahoo.elide.datastores.aggregation.timegrains.Month) Test(org.junit.jupiter.api.Test)

Example 4 with Month

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

Example 5 with Month

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

Aggregations

Month (com.yahoo.elide.datastores.aggregation.timegrains.Month)9 Test (org.junit.jupiter.api.Test)9 Argument (com.yahoo.elide.core.request.Argument)5 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)5 Query (com.yahoo.elide.datastores.aggregation.query.Query)5 PlayerStats (example.PlayerStats)5 HashMap (java.util.HashMap)5 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)4 Serde (com.yahoo.elide.core.utils.coerce.converters.Serde)4 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)4 LocalDateTime (java.time.LocalDateTime)4 TreeMap (java.util.TreeMap)4 HashSet (java.util.HashSet)3 Path (com.yahoo.elide.core.Path)2 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)2 Attribute (com.yahoo.elide.core.request.Attribute)1 Timestamp (java.sql.Timestamp)1 OffsetDateTime (java.time.OffsetDateTime)1