Search in sources :

Example 66 with DateTime

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

the class RetryQueryRunnerTest method testRetryMultiple.

@Test
public void testRetryMultiple() throws Exception {
    Map<String, Object> context = new MapMaker().makeMap();
    context.put("count", 0);
    context.put(Result.MISSING_SEGMENTS_KEY, Lists.newArrayList());
    RetryQueryRunner<Result<TimeseriesResultValue>> runner = new RetryQueryRunner<>(new QueryRunner<Result<TimeseriesResultValue>>() {

        @Override
        public Sequence<Result<TimeseriesResultValue>> run(Query<Result<TimeseriesResultValue>> query, Map<String, Object> context) {
            if ((int) context.get("count") < 3) {
                ((List) context.get(Result.MISSING_SEGMENTS_KEY)).add(new SegmentDescriptor(new Interval(178888, 1999999), "test", 1));
                context.put("count", (int) context.get("count") + 1);
                return Sequences.empty();
            } else {
                return Sequences.simple(Arrays.asList(new Result<>(new DateTime(), new TimeseriesResultValue(Maps.<String, Object>newHashMap()))));
            }
        }
    }, (QueryToolChest) new TimeseriesQueryQueryToolChest(QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator()), new RetryQueryRunnerConfig() {

        private int numTries = 4;

        private boolean returnPartialResults = true;

        public int getNumTries() {
            return numTries;
        }

        public boolean returnPartialResults() {
            return returnPartialResults;
        }
    }, jsonMapper);
    Iterable<Result<TimeseriesResultValue>> actualResults = Sequences.toList(runner.run(query, context), Lists.<Result<TimeseriesResultValue>>newArrayList());
    Assert.assertTrue("Should return a list with one element", ((List) actualResults).size() == 1);
    Assert.assertTrue("Should have nothing in missingSegment list", ((List) context.get(Result.MISSING_SEGMENTS_KEY)).size() == 0);
}
Also used : TimeseriesResultValue(io.druid.query.timeseries.TimeseriesResultValue) MapMaker(com.google.common.collect.MapMaker) Sequence(io.druid.java.util.common.guava.Sequence) TimeseriesQueryQueryToolChest(io.druid.query.timeseries.TimeseriesQueryQueryToolChest) DateTime(org.joda.time.DateTime) List(java.util.List) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 67 with DateTime

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

the class TimewarpOperatorTest method testEmptyFutureInterval.

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

        @Override
        public Sequence<Result<TimeseriesResultValue>> run(Query<Result<TimeseriesResultValue>> query, Map<String, Object> responseContext) {
            return Sequences.simple(ImmutableList.of(new Result<>(query.getIntervals().get(0).getStart(), new TimeseriesResultValue(ImmutableMap.<String, Object>of("metric", 2))), new Result<>(query.getIntervals().get(0).getEnd(), new TimeseriesResultValue(ImmutableMap.<String, Object>of("metric", 3)))));
        }
    }, new DateTime("2014-08-02").getMillis());
    final Query<Result<TimeseriesResultValue>> query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2014-08-06/2014-08-08").aggregators(Arrays.<AggregatorFactory>asList(new CountAggregatorFactory("count"))).build();
    Assert.assertEquals(Lists.newArrayList(new Result<>(new DateTime("2014-08-02"), new TimeseriesResultValue(ImmutableMap.<String, Object>of("metric", 2))), new Result<>(new DateTime("2014-08-02"), new TimeseriesResultValue(ImmutableMap.<String, Object>of("metric", 3)))), Sequences.toList(queryRunner.run(query, Maps.<String, Object>newHashMap()), Lists.<Result<TimeseriesResultValue>>newArrayList()));
}
Also used : TimeseriesResultValue(io.druid.query.timeseries.TimeseriesResultValue) Sequence(io.druid.java.util.common.guava.Sequence) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) DateTime(org.joda.time.DateTime) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) Test(org.junit.Test)

Example 68 with DateTime

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

the class TimewarpOperatorTest method testPostProcess.

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

        @Override
        public Sequence<Result<TimeseriesResultValue>> run(Query<Result<TimeseriesResultValue>> query, Map<String, Object> responseContext) {
            return Sequences.simple(ImmutableList.of(new Result<>(new DateTime(new DateTime("2014-01-09")), new TimeseriesResultValue(ImmutableMap.<String, Object>of("metric", 2))), new Result<>(new DateTime(new DateTime("2014-01-11")), new TimeseriesResultValue(ImmutableMap.<String, Object>of("metric", 3))), new Result<>(query.getIntervals().get(0).getEnd(), new TimeseriesResultValue(ImmutableMap.<String, Object>of("metric", 5)))));
        }
    }, new DateTime("2014-08-02").getMillis());
    final Query<Result<TimeseriesResultValue>> query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2014-07-31/2014-08-05").aggregators(Arrays.<AggregatorFactory>asList(new CountAggregatorFactory("count"))).build();
    Assert.assertEquals(Lists.newArrayList(new Result<>(new DateTime("2014-07-31"), new TimeseriesResultValue(ImmutableMap.<String, Object>of("metric", 2))), new Result<>(new DateTime("2014-08-02"), new TimeseriesResultValue(ImmutableMap.<String, Object>of("metric", 3))), new Result<>(new DateTime("2014-08-02"), new TimeseriesResultValue(ImmutableMap.<String, Object>of("metric", 5)))), Sequences.toList(queryRunner.run(query, CONTEXT), Lists.<Result<TimeseriesResultValue>>newArrayList()));
    TimewarpOperator<Result<TimeBoundaryResultValue>> timeBoundaryOperator = new TimewarpOperator<>(new Interval(new DateTime("2014-01-01"), new DateTime("2014-01-15")), new Period("P1W"), // align on Monday
    new DateTime("2014-01-06"));
    QueryRunner<Result<TimeBoundaryResultValue>> timeBoundaryRunner = timeBoundaryOperator.postProcess(new QueryRunner<Result<TimeBoundaryResultValue>>() {

        @Override
        public Sequence<Result<TimeBoundaryResultValue>> run(Query<Result<TimeBoundaryResultValue>> query, Map<String, Object> responseContext) {
            return Sequences.simple(ImmutableList.of(new Result<>(new DateTime("2014-01-12"), new TimeBoundaryResultValue(ImmutableMap.<String, Object>of("maxTime", new DateTime("2014-01-12"))))));
        }
    }, new DateTime("2014-08-02").getMillis());
    final Query<Result<TimeBoundaryResultValue>> timeBoundaryQuery = Druids.newTimeBoundaryQueryBuilder().dataSource("dummy").build();
    Assert.assertEquals(Lists.newArrayList(new Result<>(new DateTime("2014-08-02"), new TimeBoundaryResultValue(ImmutableMap.<String, Object>of("maxTime", new DateTime("2014-08-02"))))), Sequences.toList(timeBoundaryRunner.run(timeBoundaryQuery, CONTEXT), Lists.<Result<TimeBoundaryResultValue>>newArrayList()));
}
Also used : TimeseriesResultValue(io.druid.query.timeseries.TimeseriesResultValue) Period(org.joda.time.Period) Sequence(io.druid.java.util.common.guava.Sequence) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) DateTime(org.joda.time.DateTime) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) TimeBoundaryResultValue(io.druid.query.timeboundary.TimeBoundaryResultValue) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 69 with DateTime

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

the class DataSourceMetadataQueryTest method testResultSerialization.

@Test
public void testResultSerialization() {
    final DataSourceMetadataResultValue resultValue = new DataSourceMetadataResultValue(new DateTime("2000-01-01T00Z"));
    final Map<String, Object> resultValueMap = new DefaultObjectMapper().convertValue(resultValue, new TypeReference<Map<String, Object>>() {
    });
    Assert.assertEquals(ImmutableMap.<String, Object>of("maxIngestedEventTime", "2000-01-01T00:00:00.000Z"), resultValueMap);
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 70 with DateTime

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

the class DataSourceMetadataQueryTest method testMaxIngestedEventTime.

@Test
public void testMaxIngestedEventTime() throws Exception {
    final IncrementalIndex rtIndex = new OnheapIncrementalIndex(0L, Granularities.NONE, new AggregatorFactory[] { new CountAggregatorFactory("count") }, 1000);
    ;
    final QueryRunner runner = QueryRunnerTestHelper.makeQueryRunner((QueryRunnerFactory) new DataSourceMetadataQueryRunnerFactory(QueryRunnerTestHelper.NOOP_QUERYWATCHER), new IncrementalIndexSegment(rtIndex, "test"), null);
    DateTime timestamp = new DateTime(System.currentTimeMillis());
    rtIndex.add(new MapBasedInputRow(timestamp.getMillis(), ImmutableList.of("dim1"), ImmutableMap.<String, Object>of("dim1", "x")));
    DataSourceMetadataQuery dataSourceMetadataQuery = Druids.newDataSourceMetadataQueryBuilder().dataSource("testing").build();
    Map<String, Object> context = new MapMaker().makeMap();
    context.put(Result.MISSING_SEGMENTS_KEY, Lists.newArrayList());
    Iterable<Result<DataSourceMetadataResultValue>> results = Sequences.toList(runner.run(dataSourceMetadataQuery, context), Lists.<Result<DataSourceMetadataResultValue>>newArrayList());
    DataSourceMetadataResultValue val = results.iterator().next().getValue();
    DateTime maxIngestedEventTime = val.getMaxIngestedEventTime();
    Assert.assertEquals(timestamp, maxIngestedEventTime);
}
Also used : IncrementalIndex(io.druid.segment.incremental.IncrementalIndex) OnheapIncrementalIndex(io.druid.segment.incremental.OnheapIncrementalIndex) IncrementalIndexSegment(io.druid.segment.IncrementalIndexSegment) OnheapIncrementalIndex(io.druid.segment.incremental.OnheapIncrementalIndex) MapMaker(com.google.common.collect.MapMaker) QueryRunner(io.druid.query.QueryRunner) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) Test(org.junit.Test)

Aggregations

DateTime (org.joda.time.DateTime)5683 Test (org.junit.Test)1667 Test (org.testng.annotations.Test)774 ArrayList (java.util.ArrayList)545 Date (java.util.Date)389 LocalDate (org.joda.time.LocalDate)374 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)353 ResponseBody (okhttp3.ResponseBody)335 Interval (org.joda.time.Interval)307 Test (org.junit.jupiter.api.Test)281 HashMap (java.util.HashMap)272 BigDecimal (java.math.BigDecimal)234 DateTimeZone (org.joda.time.DateTimeZone)220 UUID (java.util.UUID)195 List (java.util.List)194 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)178 Map (java.util.Map)171 IOException (java.io.IOException)158 Result (io.druid.query.Result)153 ServiceCall (com.microsoft.rest.ServiceCall)148