Search in sources :

Example 1 with DateTimeZone

use of org.joda.time.DateTimeZone in project druid by druid-io.

the class Granularity method granularitiesFinerThan.

public static List<Granularity> granularitiesFinerThan(final Granularity gran0) {
    final DateTime epoch = new DateTime(0);
    final List<Granularity> retVal = Lists.newArrayList();
    final DateTime origin = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getOrigin() : null;
    final DateTimeZone tz = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getTimeZone() : null;
    for (GranularityType gran : GranularityType.values()) {
        /**
       * All and None are excluded b/c when asked to give all granularities finer
       * than "TEN_MINUTE", you want the answer to be "FIVE_MINUTE, MINUTE and SECOND"
       * it doesn't make sense to include ALL or None to be part of this.
       */
        if (gran == GranularityType.ALL || gran == GranularityType.NONE) {
            continue;
        }
        final Granularity segmentGranularity = gran.create(origin, tz);
        if (segmentGranularity.bucket(epoch).toDurationMillis() <= gran0.bucket(epoch).toDurationMillis()) {
            retVal.add(segmentGranularity);
        }
    }
    Collections.sort(retVal, new Comparator<Granularity>() {

        @Override
        public int compare(Granularity g1, Granularity g2) {
            return Longs.compare(g2.bucket(epoch).toDurationMillis(), g1.bucket(epoch).toDurationMillis());
        }
    });
    return retVal;
}
Also used : DateTime(org.joda.time.DateTime) DateTimeZone(org.joda.time.DateTimeZone)

Example 2 with DateTimeZone

use of org.joda.time.DateTimeZone in project druid by druid-io.

the class QueryGranularityTest method testPeriodDaylightSaving.

@Test
public void testPeriodDaylightSaving() throws Exception {
    final DateTimeZone tz = DateTimeZone.forID("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"), new DateTime("2012-11-05T00:00:00.000-08:00"), new DateTime("2012-11-06T00:00:00.000-08:00")), new PeriodGranularity(new Period("P1D"), null, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Days.days(3)).getMillis())));
    assertSameInterval(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-08:00"), new DateTime("2012-11-04T02:00:00.000-08:00"), new DateTime("2012-11-04T03:00:00.000-08:00")), new PeriodGranularity(new Period("PT1H"), null, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Hours.hours(5)).getMillis())));
    final PeriodGranularity hour = new PeriodGranularity(new Period("PT1H"), null, tz);
    assertSameDateTime(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-08:00"), new DateTime("2012-11-04T02:00:00.000-08:00"), new DateTime("2012-11-04T03:00:00.000-08:00")), Lists.newArrayList(hour.bucketStart(new DateTime("2012-11-04T00:30:00-07:00")), hour.bucketStart(new DateTime("2012-11-04T01:30:00-07:00")), hour.bucketStart(new DateTime("2012-11-04T01:30:00-08:00")), hour.bucketStart(new DateTime("2012-11-04T02:30:00-08:00")), hour.bucketStart(new DateTime("2012-11-04T03:30:00-08:00"))));
}
Also used : PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 3 with DateTimeZone

use of org.joda.time.DateTimeZone in project druid by druid-io.

the class QueryGranularityTest method testIterableMonth.

@Test
public void testIterableMonth() throws Exception {
    final DateTimeZone tz = DateTimeZone.forID("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"), new DateTime("2012-12-01T00:00:00.000-08:00"), new DateTime("2013-01-01T00:00:00.000-08:00"), new DateTime("2013-02-01T00:00:00.000-08:00")), new PeriodGranularity(new Period("P1M"), null, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Months.months(3)).getMillis())));
}
Also used : PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 4 with DateTimeZone

use of org.joda.time.DateTimeZone in project druid by druid-io.

the class QueryGranularityTest method testIterableWeek.

@Test
public void testIterableWeek() throws Exception {
    final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
    final DateTime baseTime = new DateTime("2012-11-03T10:00:00", tz);
    assertSameInterval(Lists.newArrayList(new DateTime("2012-10-29T00:00:00.000-07:00"), new DateTime("2012-11-05T00:00:00.000-08:00"), new DateTime("2012-11-12T00:00:00.000-08:00"), new DateTime("2012-11-19T00:00:00.000-08:00")), new PeriodGranularity(new Period("P1W"), null, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Weeks.weeks(3)).getMillis())));
    assertSameInterval(Lists.newArrayList(new DateTime("2012-11-03T10:00:00.000-07:00"), new DateTime("2012-11-10T10:00:00.000-08:00"), new DateTime("2012-11-17T10:00:00.000-08:00")), new PeriodGranularity(new Period("P1W"), baseTime, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Weeks.weeks(3)).getMillis())));
}
Also used : PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 5 with DateTimeZone

use of org.joda.time.DateTimeZone in project druid by druid-io.

the class GroupByQueryRunnerTest method testGroupByWithTimeZone.

@Test
public void testGroupByWithTimeZone() {
    DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
    GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setInterval("2011-03-31T00:00:00-07:00/2011-04-02T00:00:00-07:00").setDimensions(Lists.newArrayList((DimensionSpec) new DefaultDimensionSpec("quality", "alias"))).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).setGranularity(new PeriodGranularity(new Period("P1D"), null, tz)).build();
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-03-31", tz), "alias", "automotive", "rows", 1L, "idx", 135L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-03-31", tz), "alias", "business", "rows", 1L, "idx", 118L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-03-31", tz), "alias", "entertainment", "rows", 1L, "idx", 158L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-03-31", tz), "alias", "health", "rows", 1L, "idx", 120L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-03-31", tz), "alias", "mezzanine", "rows", 3L, "idx", 2870L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-03-31", tz), "alias", "news", "rows", 1L, "idx", 121L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-03-31", tz), "alias", "premium", "rows", 3L, "idx", 2900L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-03-31", tz), "alias", "technology", "rows", 1L, "idx", 78L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-03-31", tz), "alias", "travel", "rows", 1L, "idx", 119L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-04-01", tz), "alias", "automotive", "rows", 1L, "idx", 147L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-04-01", tz), "alias", "business", "rows", 1L, "idx", 112L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-04-01", tz), "alias", "entertainment", "rows", 1L, "idx", 166L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-04-01", tz), "alias", "health", "rows", 1L, "idx", 113L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-04-01", tz), "alias", "mezzanine", "rows", 3L, "idx", 2447L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-04-01", tz), "alias", "news", "rows", 1L, "idx", 114L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-04-01", tz), "alias", "premium", "rows", 3L, "idx", 2505L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-04-01", tz), "alias", "technology", "rows", 1L, "idx", 97L), GroupByQueryRunnerTestHelper.createExpectedRow(new DateTime("2011-04-01", tz), "alias", "travel", "rows", 1L, "idx", 126L));
    Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "");
}
Also used : LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) Row(io.druid.data.input.Row) DateTimeZone(org.joda.time.DateTimeZone) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DateTimeZone (org.joda.time.DateTimeZone)392 DateTime (org.joda.time.DateTime)206 Test (org.testng.annotations.Test)59 ArrayList (java.util.ArrayList)57 Test (org.junit.Test)45 LocalDate (org.joda.time.LocalDate)34 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)30 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)24 HashMap (java.util.HashMap)20 IOException (java.io.IOException)19 UUID (java.util.UUID)19 Date (java.util.Date)17 Map (java.util.Map)17 Period (org.joda.time.Period)16 List (java.util.List)15 TimeIntervalRounding (org.elasticsearch.common.rounding.Rounding.TimeIntervalRounding)14 TimeUnitRounding (org.elasticsearch.common.rounding.Rounding.TimeUnitRounding)14 TimeFormat (org.gephi.graph.api.TimeFormat)14 LocalDateTime (org.joda.time.LocalDateTime)14 Account (org.killbill.billing.account.api.Account)14