Search in sources :

Example 1 with PeriodGranularity

use of io.druid.java.util.common.granularity.PeriodGranularity in project druid by druid-io.

the class VarianceGroupByQueryTest method testPostAggHavingSpec.

@Test
public void testPostAggHavingSpec() {
    VarianceTestHelper.RowBuilder expect = new VarianceTestHelper.RowBuilder(new String[] { "alias", "rows", "index", "index_var", "index_stddev" });
    List<Row> expectedResults = expect.add("2011-04-01", "automotive", 2L, 269L, 299.0009819048282, 17.29164485827847).add("2011-04-01", "mezzanine", 6L, 4420L, 254083.76447001836, 504.06722217380724).add("2011-04-01", "premium", 6L, 4416L, 252279.2020389339, 502.27403082275106).build();
    GroupByQuery query = GroupByQuery.builder().setDataSource(VarianceTestHelper.dataSource).setInterval("2011-04-02/2011-04-04").setDimensions(Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("quality", "alias"))).setAggregatorSpecs(Arrays.asList(VarianceTestHelper.rowsCount, VarianceTestHelper.indexLongSum, VarianceTestHelper.indexVarianceAggr)).setPostAggregatorSpecs(ImmutableList.<PostAggregator>of(VarianceTestHelper.stddevOfIndexPostAggr)).setGranularity(new PeriodGranularity(new Period("P1M"), null, null)).setHavingSpec(new OrHavingSpec(ImmutableList.<HavingSpec>of(// 3 rows
    new GreaterThanHavingSpec(VarianceTestHelper.stddevOfIndexMetric, 15L)))).build();
    Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "");
    query = query.withLimitSpec(new DefaultLimitSpec(Arrays.<OrderByColumnSpec>asList(OrderByColumnSpec.asc(VarianceTestHelper.stddevOfIndexMetric)), 2));
    expectedResults = expect.add("2011-04-01", "automotive", 2L, 269L, 299.0009819048282, 17.29164485827847).add("2011-04-01", "premium", 6L, 4416L, 252279.2020389339, 502.27403082275106).build();
    results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "");
}
Also used : DimensionSpec(io.druid.query.dimension.DimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) OrHavingSpec(io.druid.query.groupby.having.OrHavingSpec) PostAggregator(io.druid.query.aggregation.PostAggregator) DefaultLimitSpec(io.druid.query.groupby.orderby.DefaultLimitSpec) PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) GroupByQuery(io.druid.query.groupby.GroupByQuery) GreaterThanHavingSpec(io.druid.query.groupby.having.GreaterThanHavingSpec) Row(io.druid.data.input.Row) Test(org.junit.Test) GroupByQueryRunnerTest(io.druid.query.groupby.GroupByQueryRunnerTest)

Example 2 with PeriodGranularity

use of io.druid.java.util.common.granularity.PeriodGranularity in project druid by druid-io.

the class IntervalChunkingQueryRunner method splitInterval.

private Iterable<Interval> splitInterval(Interval interval, Period period) {
    if (interval.getEndMillis() == interval.getStartMillis()) {
        return Lists.newArrayList(interval);
    }
    List<Interval> intervals = Lists.newArrayList();
    Iterator<Interval> timestamps = new PeriodGranularity(period, null, null).getIterable(interval).iterator();
    long start = Math.max(timestamps.next().getStartMillis(), interval.getStartMillis());
    while (timestamps.hasNext()) {
        long end = timestamps.next().getStartMillis();
        intervals.add(new Interval(start, end));
        start = end;
    }
    if (start < interval.getEndMillis()) {
        intervals.add(new Interval(start, interval.getEndMillis()));
    }
    return intervals;
}
Also used : PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Interval(org.joda.time.Interval)

Example 3 with PeriodGranularity

use of io.druid.java.util.common.granularity.PeriodGranularity 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 4 with PeriodGranularity

use of io.druid.java.util.common.granularity.PeriodGranularity 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 5 with PeriodGranularity

use of io.druid.java.util.common.granularity.PeriodGranularity 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)

Aggregations

PeriodGranularity (io.druid.java.util.common.granularity.PeriodGranularity)41 Period (org.joda.time.Period)39 Test (org.junit.Test)36 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)26 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)20 DateTime (org.joda.time.DateTime)19 Row (io.druid.data.input.Row)18 Interval (org.joda.time.Interval)18 FinalizeResultsQueryRunner (io.druid.query.FinalizeResultsQueryRunner)9 QueryRunner (io.druid.query.QueryRunner)9 Result (io.druid.query.Result)9 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)9 DimensionSpec (io.druid.query.dimension.DimensionSpec)8 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)7 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)7 DimFilterHavingSpec (io.druid.query.groupby.having.DimFilterHavingSpec)7 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)6 GreaterThanHavingSpec (io.druid.query.groupby.having.GreaterThanHavingSpec)6 OrHavingSpec (io.druid.query.groupby.having.OrHavingSpec)6 MergeSequence (io.druid.java.util.common.guava.MergeSequence)5