Search in sources :

Example 6 with Month

use of com.yahoo.elide.datastores.aggregation.timegrains.Month in project elide by yahoo.

the class QueryEngineTest method testMultipleTimeGrainsFilteredByMonthAlias.

@Test
public void testMultipleTimeGrainsFilteredByMonthAlias() 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", "byMonth", new HashSet<>(monthArguments.values())), Operator.IN, Lists.newArrayList(new Day(Date.valueOf("2019-07-01"))));
    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(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 : 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 7 with Month

use of com.yahoo.elide.datastores.aggregation.timegrains.Month in project elide by yahoo.

the class MonthSerdeTest method testDeserializeOffsetDateTime.

@Test
public void testDeserializeOffsetDateTime() {
    LocalDateTime localDate = LocalDateTime.of(2020, java.time.Month.of(01), 01, 00, 00, 00);
    Month expectedDate = new Month(localDate);
    OffsetDateTime dateTime = OffsetDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
    Serde serde = new Month.MonthSerde();
    Object actualDate = serde.deserialize(dateTime);
    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) OffsetDateTime(java.time.OffsetDateTime) Test(org.junit.jupiter.api.Test)

Example 8 with Month

use of com.yahoo.elide.datastores.aggregation.timegrains.Month in project elide by yahoo.

the class MonthSerdeTest method testDeserializeTimestamp.

@Test
public void testDeserializeTimestamp() {
    LocalDateTime localDate = LocalDateTime.of(2020, java.time.Month.of(01), 01, 00, 00, 00);
    Month expectedDate = new Month(localDate);
    Timestamp timestamp = new Timestamp(expectedDate.getTime());
    Serde serde = new Month.MonthSerde();
    Object actualDate = serde.deserialize(timestamp);
    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) Timestamp(java.sql.Timestamp) Test(org.junit.jupiter.api.Test)

Example 9 with Month

use of com.yahoo.elide.datastores.aggregation.timegrains.Month in project elide by yahoo.

the class MonthSerdeTest method testDateSerialize.

@Test
public void testDateSerialize() {
    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 actual = serde.serialize(expectedDate);
    assertEquals("2020-01", actual);
}
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)

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