use of org.apache.druid.java.util.common.granularity.PeriodGranularity in project druid by druid-io.
the class QueryGranularityTest method testPeriodDaylightSaving.
@Test
public void testPeriodDaylightSaving() {
final DateTimeZone tz = DateTimes.inferTzFromString("America/Los_Angeles");
final DateTime baseTime = new DateTime("2012-11-04T00:00:00", tz);
assertSameInterval(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00", tz), new DateTime("2012-11-05T00:00:00.000-08:00", tz), new DateTime("2012-11-06T00:00:00.000-08:00", tz)), new PeriodGranularity(new Period("P1D"), null, tz).getIterable(new Interval(baseTime, baseTime.plus(Days.days(3)))));
assertSameInterval(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00", tz), new DateTime("2012-11-04T01:00:00.000-07:00", tz), new DateTime("2012-11-04T01:00:00.000-08:00", tz), new DateTime("2012-11-04T02:00:00.000-08:00", tz), new DateTime("2012-11-04T03:00:00.000-08:00", tz)), new PeriodGranularity(new Period("PT1H"), null, tz).getIterable(new Interval(baseTime, baseTime.plus(Hours.hours(5)))));
final PeriodGranularity hour = new PeriodGranularity(new Period("PT1H"), null, tz);
assertSameDateTime(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00", tz), new DateTime("2012-11-04T01:00:00.000-07:00", tz), new DateTime("2012-11-04T01:00:00.000-08:00", tz), new DateTime("2012-11-04T02:00:00.000-08:00", tz), new DateTime("2012-11-04T03:00:00.000-08:00", tz)), Lists.newArrayList(hour.bucketStart(DateTimes.of("2012-11-04T00:30:00-07:00")), hour.bucketStart(DateTimes.of("2012-11-04T01:30:00-07:00")), hour.bucketStart(DateTimes.of("2012-11-04T01:30:00-08:00")), hour.bucketStart(DateTimes.of("2012-11-04T02:30:00-08:00")), hour.bucketStart(DateTimes.of("2012-11-04T03:30:00-08:00"))));
}
use of org.apache.druid.java.util.common.granularity.PeriodGranularity in project druid by druid-io.
the class QueryGranularityTest method testIterableMonth.
@Test
public void testIterableMonth() {
final DateTimeZone tz = DateTimes.inferTzFromString("America/Los_Angeles");
final DateTime baseTime = new DateTime("2012-11-03T10:00:00", tz);
assertSameInterval(Lists.newArrayList(new DateTime("2012-11-01T00:00:00.000-07:00", tz), new DateTime("2012-12-01T00:00:00.000-08:00", tz), new DateTime("2013-01-01T00:00:00.000-08:00", tz), new DateTime("2013-02-01T00:00:00.000-08:00", tz)), new PeriodGranularity(new Period("P1M"), null, tz).getIterable(new Interval(baseTime, baseTime.plus(Months.months(3)))));
}
use of org.apache.druid.java.util.common.granularity.PeriodGranularity in project druid by druid-io.
the class QueryGranularityTest method testSerializePeriod.
@Test
public void testSerializePeriod() throws Exception {
final ObjectMapper mapper = new DefaultObjectMapper();
String json = "{ \"type\": \"period\", \"period\": \"P1D\" }";
Granularity gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new PeriodGranularity(new Period("P1D"), null, null), gran);
// Nonstandard period
json = "{ \"type\": \"period\", \"period\": \"P2D\" }";
gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new PeriodGranularity(new Period("P2D"), null, null), gran);
// Set timeZone, origin
json = "{ \"type\": \"period\", \"period\": \"P1D\"," + "\"timeZone\": \"America/Los_Angeles\", \"origin\": \"1970-01-01T00:00:00Z\"}";
gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new PeriodGranularity(new Period("P1D"), DateTimes.EPOCH, DateTimes.inferTzFromString("America/Los_Angeles")), gran);
PeriodGranularity expected = new PeriodGranularity(new Period("P1D"), DateTimes.of("2012-01-01"), DateTimes.inferTzFromString("America/Los_Angeles"));
String jsonOut = mapper.writeValueAsString(expected);
Assert.assertEquals(expected, mapper.readValue(jsonOut, Granularity.class));
String illegalJson = "{ \"type\": \"period\", \"period\": \"P0D\" }";
try {
mapper.readValue(illegalJson, Granularity.class);
Assert.fail();
} catch (JsonMappingException e) {
}
}
use of org.apache.druid.java.util.common.granularity.PeriodGranularity in project druid by druid-io.
the class QueryGranularityTest method testTruncateKathmandu.
@Test
public void testTruncateKathmandu() {
final DateTimeZone tz = DateTimeZone.forTimeZone(TimeZone.getTimeZone("Asia/Kathmandu"));
final DateTime date = new DateTime("2011-03-15T21:42:23.898+05:45", tz);
final PeriodGranularity year = new PeriodGranularity(new Period("P1Y"), null, tz);
final PeriodGranularity hour = new PeriodGranularity(new Period("PT1H"), null, tz);
final PeriodGranularity twoHour = new PeriodGranularity(new Period("PT2H"), null, tz);
assertBucketStart(year, date, new DateTime("2011-01-01T00:00:00.000+05:45", tz));
assertBucketStart(hour, date, new DateTime("2011-03-15T21:00:00.000+05:45", tz));
assertBucketStart(twoHour, date, new DateTime("2011-03-15T20:00:00.000+05:45", tz));
}
use of org.apache.druid.java.util.common.granularity.PeriodGranularity in project druid by druid-io.
the class QueryGranularityTest method testPeriodTruncateMinutes.
@Test
public void testPeriodTruncateMinutes() {
final DateTime origin = DateTimes.of("2012-01-02T00:05:00.000Z");
PeriodGranularity periodOrigin = new PeriodGranularity(new Period("PT15M"), origin, null);
assertSameDateTime(Lists.newArrayList(DateTimes.of("2012-01-01T04:50:00.000Z"), DateTimes.of("2012-01-02T07:05:00.000Z"), DateTimes.of("2012-01-04T00:20:00.000Z")), Lists.newArrayList(periodOrigin.bucketStart(DateTimes.of("2012-01-01T05:00:04.123Z")), periodOrigin.bucketStart(DateTimes.of("2012-01-02T07:08:04.123Z")), periodOrigin.bucketStart(DateTimes.of("2012-01-04T00:20:04.123Z"))));
PeriodGranularity periodNoOrigin = new PeriodGranularity(new Period("PT15M"), null, null);
assertSameDateTime(Lists.newArrayList(DateTimes.of("2012-01-01T05:00:00.000Z"), DateTimes.of("2012-01-02T07:00:00.000Z"), DateTimes.of("2012-01-04T00:15:00.000Z")), Lists.newArrayList(periodNoOrigin.bucketStart(DateTimes.of("2012-01-01T05:00:04.123Z")), periodNoOrigin.bucketStart(DateTimes.of("2012-01-02T07:00:04.123Z")), periodNoOrigin.bucketStart(DateTimes.of("2012-01-04T00:20:04.123Z"))));
}
Aggregations