Search in sources :

Example 56 with PeriodGranularity

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

the class DetermineHashedPartitionsJobTest method data.

@Parameterized.Parameters(name = "File={0}, TargetPartitionSize={1}, Interval={2}, ErrorMargin={3}, NumTimeBuckets={4}, NumShards={5}, SegmentGranularity={6}")
public static Collection<?> data() {
    int[] first = new int[1];
    Arrays.fill(first, 13);
    int[] second = new int[6];
    Arrays.fill(second, 1);
    int[] third = new int[6];
    Arrays.fill(third, 13);
    third[2] = 12;
    third[5] = 11;
    return Arrays.asList(new Object[][] { { DetermineHashedPartitionsJobTest.class.getResource("/druid.test.data.with.duplicate.rows.tsv").getPath(), 1, "2011-04-10T00:00:00.000Z/2011-04-11T00:00:00.000Z", 0, 1, first, Granularities.DAY, null }, { DetermineHashedPartitionsJobTest.class.getResource("/druid.test.data.with.duplicate.rows.tsv").getPath(), 100, "2011-04-10T00:00:00.000Z/2011-04-16T00:00:00.000Z", 0, 6, second, Granularities.DAY, null }, { DetermineHashedPartitionsJobTest.class.getResource("/druid.test.data.with.duplicate.rows.tsv").getPath(), 1, "2011-04-10T00:00:00.000Z/2011-04-16T00:00:00.000Z", 0, 6, third, Granularities.DAY, null }, { DetermineHashedPartitionsJobTest.class.getResource("/druid.test.data.with.duplicate.rows.tsv").getPath(), 1, null, 0, 6, third, Granularities.DAY, null }, { DetermineHashedPartitionsJobTest.class.getResource("/druid.test.data.with.duplicate.rows.tsv").getPath(), 1, null, 0, 6, third, Granularities.DAY, HashPartitionFunction.MURMUR3_32_ABS }, { DetermineHashedPartitionsJobTest.class.getResource("/druid.test.data.with.rows.in.timezone.tsv").getPath(), 1, null, 0, 1, first, new PeriodGranularity(new Period("P1D"), null, DateTimes.inferTzFromString("America/Los_Angeles")), null } });
}
Also used : PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period)

Example 57 with PeriodGranularity

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

the class TimewarpOperatorTest method testPostProcessWithTimezonesAndDstShift.

@Test
public void testPostProcessWithTimezonesAndDstShift() {
    QueryRunner<Result<TimeseriesResultValue>> queryRunner = testOperator.postProcess(new QueryRunner<Result<TimeseriesResultValue>>() {

        @Override
        public Sequence<Result<TimeseriesResultValue>> run(QueryPlus<Result<TimeseriesResultValue>> queryPlus, ResponseContext responseContext) {
            return Sequences.simple(ImmutableList.of(new Result<>(DateTimes.of("2014-01-09T-08"), new TimeseriesResultValue(ImmutableMap.of("metric", 2))), new Result<>(DateTimes.of("2014-01-11T-08"), new TimeseriesResultValue(ImmutableMap.of("metric", 3))), new Result<>(queryPlus.getQuery().getIntervals().get(0).getEnd(), new TimeseriesResultValue(ImmutableMap.of("metric", 5)))));
        }
    }, DateTimes.of("2014-08-02T-07").getMillis());
    final Query<Result<TimeseriesResultValue>> query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2014-07-31T-07/2014-08-05T-07").granularity(new PeriodGranularity(new Period("P1D"), null, DateTimes.inferTzFromString("America/Los_Angeles"))).aggregators(Collections.singletonList(new CountAggregatorFactory("count"))).build();
    Assert.assertEquals(Lists.newArrayList(new Result<>(DateTimes.of("2014-07-31T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 2))), new Result<>(DateTimes.of("2014-08-02T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 3))), new Result<>(DateTimes.of("2014-08-02T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 5)))), queryRunner.run(QueryPlus.wrap(query)).toList());
}
Also used : TimeseriesResultValue(org.apache.druid.query.timeseries.TimeseriesResultValue) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) ResponseContext(org.apache.druid.query.context.ResponseContext) PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) Sequence(org.apache.druid.java.util.common.guava.Sequence) Test(org.junit.Test)

Example 58 with PeriodGranularity

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

the class TimewarpOperatorTest method testPostProcessWithTimezonesAndNoDstShift.

@Test
public void testPostProcessWithTimezonesAndNoDstShift() {
    QueryRunner<Result<TimeseriesResultValue>> queryRunner = testOperator.postProcess(new QueryRunner<Result<TimeseriesResultValue>>() {

        @Override
        public Sequence<Result<TimeseriesResultValue>> run(QueryPlus<Result<TimeseriesResultValue>> queryPlus, ResponseContext responseContext) {
            return Sequences.simple(ImmutableList.of(new Result<>(DateTimes.of("2014-01-09T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 2))), new Result<>(DateTimes.of("2014-01-11T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 3))), new Result<>(queryPlus.getQuery().getIntervals().get(0).getEnd(), new TimeseriesResultValue(ImmutableMap.of("metric", 5)))));
        }
    }, DateTimes.of("2014-08-02T-07").getMillis());
    final Query<Result<TimeseriesResultValue>> query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2014-07-31T-07/2014-08-05T-07").granularity(new PeriodGranularity(new Period("P1D"), null, DateTimes.inferTzFromString("America/Phoenix"))).aggregators(Collections.singletonList(new CountAggregatorFactory("count"))).build();
    Assert.assertEquals(Lists.newArrayList(new Result<>(DateTimes.of("2014-07-31T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 2))), new Result<>(DateTimes.of("2014-08-02T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 3))), new Result<>(DateTimes.of("2014-08-02T-07"), new TimeseriesResultValue(ImmutableMap.of("metric", 5)))), queryRunner.run(QueryPlus.wrap(query)).toList());
}
Also used : TimeseriesResultValue(org.apache.druid.query.timeseries.TimeseriesResultValue) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) ResponseContext(org.apache.druid.query.context.ResponseContext) PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) Sequence(org.apache.druid.java.util.common.guava.Sequence) Test(org.junit.Test)

Example 59 with PeriodGranularity

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

the class CalciteQueryTest method testAvgDailyCountDistinct.

@Test
public void testAvgDailyCountDistinct() throws Exception {
    // Cannot vectorize outer query due to inlined inner query.
    cannotVectorize();
    testQuery("SELECT\n" + "  AVG(u)\n" + "FROM (SELECT FLOOR(__time TO DAY), APPROX_COUNT_DISTINCT(cnt) AS u FROM druid.foo GROUP BY 1)", ImmutableList.of(GroupByQuery.builder().setDataSource(new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(new PeriodGranularity(Period.days(1), null, DateTimeZone.UTC)).aggregators(new CardinalityAggregatorFactory("a0:a", null, dimensions(new DefaultDimensionSpec("cnt", "cnt", ColumnType.LONG)), false, true)).postAggregators(ImmutableList.of(new HyperUniqueFinalizingPostAggregator("a0", "a0:a"))).context(getTimeseriesContextWithFloorTime(TIMESERIES_CONTEXT_BY_GRAN, "d0")).build())).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(useDefault ? aggregators(new LongSumAggregatorFactory("_a0:sum", "a0"), new CountAggregatorFactory("_a0:count")) : aggregators(new LongSumAggregatorFactory("_a0:sum", "a0"), new FilteredAggregatorFactory(new CountAggregatorFactory("_a0:count"), not(selector("a0", null, null))))).setPostAggregatorSpecs(ImmutableList.of(new ArithmeticPostAggregator("_a0", "quotient", ImmutableList.of(new FieldAccessPostAggregator(null, "_a0:sum"), new FieldAccessPostAggregator(null, "_a0:count"))))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 1L }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) ArithmeticPostAggregator(org.apache.druid.query.aggregation.post.ArithmeticPostAggregator) FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) HyperUniqueFinalizingPostAggregator(org.apache.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator) CardinalityAggregatorFactory(org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 60 with PeriodGranularity

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

the class CalciteQueryTest method testTimeStampAddConversion.

/**
 * TIMESTAMPADD is converted to timestamp_shift function call and its parameters will be converted to a Period string or an expression
 * see https://github.com/apache/druid/issues/10530 for more information
 */
@Test
public void testTimeStampAddConversion() throws Exception {
    final PeriodGranularity periodGranularity = new PeriodGranularity(new Period("P1M"), null, null);
    // 
    // 2nd parameter for TIMESTAMPADD is literal, it will be translated to 'P1M' string
    // 
    testQuery("SELECT TIMESTAMPADD(MONTH, 1, \"__time\") FROM druid.foo", // verify if SQL matches given native query
    ImmutableList.of(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).virtualColumns(expressionVirtualColumn("v0", "timestamp_shift(\"__time\",'P1M',1,'UTC')", ColumnType.LONG)).columns("v0").resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).context(QUERY_CONTEXT_DEFAULT).build()), // verify if query results match the given
    CalciteTests.ROWS1.stream().map(r -> new Object[] { periodGranularity.increment(r.getTimestamp()).getMillis() }).collect(Collectors.toList()));
    // 
    // 2nd parameter for TIMESTAMPADD is an expression, it will be explained as a function call: concat('P', (1 * \"cnt\"), 'M')
    // 
    testQuery("SELECT TIMESTAMPADD(MONTH, \"cnt\", \"__time\") FROM druid.foo", // verify if SQL matches given native query
    ImmutableList.of(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).virtualColumns(expressionVirtualColumn("v0", "timestamp_shift(\"__time\",concat('P', (1 * \"cnt\"), 'M'),1,'UTC')", ColumnType.LONG)).columns("v0").resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).context(QUERY_CONTEXT_DEFAULT).build()), // "cnt" for each row is 1
    CalciteTests.ROWS1.stream().map(row -> new Object[] { periodGranularity.increment(row.getTimestamp()).getMillis() }).collect(Collectors.toList()));
}
Also used : PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) Test(org.junit.Test)

Aggregations

PeriodGranularity (org.apache.druid.java.util.common.granularity.PeriodGranularity)65 Test (org.junit.Test)57 Period (org.joda.time.Period)52 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)33 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)27 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)24 DateTime (org.joda.time.DateTime)13 QueryRunner (org.apache.druid.query.QueryRunner)11 Result (org.apache.druid.query.Result)11 ArrayList (java.util.ArrayList)10 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)10 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)10 ResponseContext (org.apache.druid.query.context.ResponseContext)9 DateTimeZone (org.joda.time.DateTimeZone)9 ChainedExecutionQueryRunner (org.apache.druid.query.ChainedExecutionQueryRunner)8 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)8 Sequence (org.apache.druid.java.util.common.guava.Sequence)7 QueryPlus (org.apache.druid.query.QueryPlus)7 Interval (org.joda.time.Interval)7 QueryDataSource (org.apache.druid.query.QueryDataSource)6