Search in sources :

Example 16 with PeriodGranularity

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

the class HadoopIngestionSpecTest method testPeriodSegmentGranularitySpec.

@Test
public void testPeriodSegmentGranularitySpec() {
    final HadoopIngestionSpec schema;
    try {
        schema = jsonReadWriteRead("{\n" + "    \"dataSchema\": {\n" + "     \"dataSource\": \"foo\",\n" + "     \"metricsSpec\": [],\n" + "        \"granularitySpec\": {\n" + "                \"type\": \"uniform\",\n" + "                \"segmentGranularity\": {\"type\": \"period\", \"period\":\"PT1H\", \"timeZone\":\"America/Los_Angeles\"},\n" + "                \"intervals\": [\"2012-01-01/P1D\"]\n" + "        }\n" + "    }\n" + "}", HadoopIngestionSpec.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    final UniformGranularitySpec granularitySpec = (UniformGranularitySpec) schema.getDataSchema().getGranularitySpec();
    Assert.assertEquals("getSegmentGranularity", new PeriodGranularity(new Period("PT1H"), null, DateTimeZone.forID("America/Los_Angeles")), granularitySpec.getSegmentGranularity());
}
Also used : UniformGranularitySpec(io.druid.segment.indexing.granularity.UniformGranularitySpec) PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test)

Example 17 with PeriodGranularity

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

the class GranularityPathSpecTest method testBackwardCompatiblePeriodSegmentGranularitySerialization.

@Test
public void testBackwardCompatiblePeriodSegmentGranularitySerialization() throws JsonProcessingException {
    final PeriodGranularity pt2S = new PeriodGranularity(new Period("PT2S"), null, DateTimeZone.UTC);
    Assert.assertNotEquals("\"SECOND\"", jsonMapper.writeValueAsString(pt2S));
    final Granularity pt1S = Granularities.SECOND;
    Assert.assertEquals("\"SECOND\"", jsonMapper.writeValueAsString(pt1S));
}
Also used : PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) Granularity(io.druid.java.util.common.granularity.Granularity) PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Test(org.junit.Test)

Example 18 with PeriodGranularity

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

the class TimeseriesQueryRunnerTest method testTimeseriesWithVaryingGran.

@Test
public void testTimeseriesWithVaryingGran() {
    TimeseriesQuery query1 = Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(new PeriodGranularity(new Period("P1M"), null, null)).intervals(Arrays.asList(new Interval("2011-04-02T00:00:00.000Z/2011-04-03T00:00:00.000Z"))).aggregators(Arrays.<AggregatorFactory>asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"), QueryRunnerTestHelper.qualityUniques)).descending(descending).build();
    List<Result<TimeseriesResultValue>> expectedResults1 = Arrays.asList(new Result<>(new DateTime("2011-04-01"), new TimeseriesResultValue(ImmutableMap.<String, Object>of("rows", 13L, "idx", 5827L, "uniques", QueryRunnerTestHelper.UNIQUES_9))));
    Iterable<Result<TimeseriesResultValue>> results1 = Sequences.toList(runner.run(query1, CONTEXT), Lists.<Result<TimeseriesResultValue>>newArrayList());
    assertExpectedResults(expectedResults1, results1);
    TimeseriesQuery query2 = Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity("DAY").intervals(Arrays.asList(new Interval("2011-04-02T00:00:00.000Z/2011-04-03T00:00:00.000Z"))).aggregators(Arrays.<AggregatorFactory>asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"), QueryRunnerTestHelper.qualityUniques)).build();
    List<Result<TimeseriesResultValue>> expectedResults2 = Arrays.asList(new Result<>(new DateTime("2011-04-02"), new TimeseriesResultValue(ImmutableMap.<String, Object>of("rows", 13L, "idx", 5827L, "uniques", QueryRunnerTestHelper.UNIQUES_9))));
    Iterable<Result<TimeseriesResultValue>> results2 = Sequences.toList(runner.run(query2, CONTEXT), Lists.<Result<TimeseriesResultValue>>newArrayList());
    assertExpectedResults(expectedResults2, results2);
}
Also used : PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) Period(org.joda.time.Period) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) DoubleFirstAggregatorFactory(io.druid.query.aggregation.first.DoubleFirstAggregatorFactory) DoubleMaxAggregatorFactory(io.druid.query.aggregation.DoubleMaxAggregatorFactory) FilteredAggregatorFactory(io.druid.query.aggregation.FilteredAggregatorFactory) DoubleMinAggregatorFactory(io.druid.query.aggregation.DoubleMinAggregatorFactory) DoubleLastAggregatorFactory(io.druid.query.aggregation.last.DoubleLastAggregatorFactory) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Result(io.druid.query.Result) Test(org.junit.Test)

Example 19 with PeriodGranularity

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

the class TimeseriesQueryRunnerTest method testTimeseriesGranularityNotAlignedOnSegmentBoundariesWithFilter.

@Test
public void testTimeseriesGranularityNotAlignedOnSegmentBoundariesWithFilter() {
    TimeseriesQuery query1 = Druids.newTimeseriesQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).filters(QueryRunnerTestHelper.marketDimension, "spot", "upfront", "total_market").granularity(new PeriodGranularity(new Period("P7D"), null, DateTimeZone.forID("America/Los_Angeles"))).intervals(Arrays.asList(new Interval("2011-01-12T00:00:00.000-08:00/2011-01-20T00:00:00.000-08:00"))).aggregators(Arrays.<AggregatorFactory>asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).descending(descending).build();
    List<Result<TimeseriesResultValue>> expectedResults1 = Arrays.asList(new Result<>(new DateTime("2011-01-06T00:00:00.000-08:00", DateTimeZone.forID("America/Los_Angeles")), new TimeseriesResultValue(ImmutableMap.<String, Object>of("rows", 13L, "idx", 6071L))), new Result<>(new DateTime("2011-01-13T00:00:00.000-08:00", DateTimeZone.forID("America/Los_Angeles")), new TimeseriesResultValue(ImmutableMap.<String, Object>of("rows", 91L, "idx", 33382L))));
    Iterable<Result<TimeseriesResultValue>> results1 = Sequences.toList(runner.run(query1, CONTEXT), Lists.<Result<TimeseriesResultValue>>newArrayList());
    assertExpectedResults(expectedResults1, results1);
}
Also used : PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) Period(org.joda.time.Period) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Result(io.druid.query.Result) Test(org.junit.Test)

Example 20 with PeriodGranularity

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

the class AbstractWorkerResourceManagementStrategy method startManagement.

@Override
public void startManagement(final WorkerTaskRunner runner) {
    if (!lifecycleLock.canStart()) {
        return;
    }
    try {
        log.info("Started Resource Management Scheduler");
        ScheduledExecutors.scheduleAtFixedRate(exec, resourceManagementSchedulerConfig.getProvisionPeriod().toStandardDuration(), new Runnable() {

            @Override
            public void run() {
                // Any Errors are caught by ScheduledExecutors
                doProvision(runner);
            }
        });
        // Schedule termination of worker nodes periodically
        Period period = resourceManagementSchedulerConfig.getTerminatePeriod();
        PeriodGranularity granularity = new PeriodGranularity(period, resourceManagementSchedulerConfig.getOriginTime(), null);
        final long startTime = granularity.bucketEnd(new DateTime()).getMillis();
        ScheduledExecutors.scheduleAtFixedRate(exec, new Duration(System.currentTimeMillis(), startTime), resourceManagementSchedulerConfig.getTerminatePeriod().toStandardDuration(), new Runnable() {

            @Override
            public void run() {
                // Any Errors are caught by ScheduledExecutors
                doTerminate(runner);
            }
        });
        lifecycleLock.started();
    } finally {
        lifecycleLock.exitStart();
    }
}
Also used : PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) Duration(org.joda.time.Duration) DateTime(org.joda.time.DateTime)

Aggregations

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