Search in sources :

Example 21 with SegmentDescriptor

use of io.druid.query.SegmentDescriptor in project druid by druid-io.

the class QuerySegmentSpecTest method testSerializationSegments.

@Test
public void testSerializationSegments() throws Exception {
    QuerySegmentSpec spec = jsonMapper.convertValue(ImmutableMap.<String, Object>of("type", "segments", "segments", ImmutableList.<Map<String, Object>>of(ImmutableMap.<String, Object>of("itvl", "2011-07-01/2011-10-10", "ver", "1", "part", 0), ImmutableMap.<String, Object>of("itvl", "2011-07-01/2011-10-10", "ver", "1", "part", 1), ImmutableMap.<String, Object>of("itvl", "2011-11-01/2011-11-10", "ver", "2", "part", 10))), QuerySegmentSpec.class);
    Assert.assertTrue(spec instanceof MultipleSpecificSegmentSpec);
    Assert.assertEquals(ImmutableList.of(new Interval("2011-07-01/2011-10-10"), new Interval("2011-11-01/2011-11-10")), spec.getIntervals());
    Assert.assertEquals(ImmutableList.of(new SegmentDescriptor(new Interval("2011-07-01/2011-10-10"), "1", 0), new SegmentDescriptor(new Interval("2011-07-01/2011-10-10"), "1", 1), new SegmentDescriptor(new Interval("2011-11-01/2011-11-10"), "2", 10)), ((MultipleSpecificSegmentSpec) spec).getDescriptors());
}
Also used : SegmentDescriptor(io.druid.query.SegmentDescriptor) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 22 with SegmentDescriptor

use of io.druid.query.SegmentDescriptor in project druid by druid-io.

the class SpecificSegmentQueryRunnerTest method testRetry.

@Test
public void testRetry() throws Exception {
    final ObjectMapper mapper = new DefaultObjectMapper();
    SegmentDescriptor descriptor = new SegmentDescriptor(new Interval("2012-01-01T00:00:00Z/P1D"), "version", 0);
    final SpecificSegmentQueryRunner queryRunner = new SpecificSegmentQueryRunner(new QueryRunner() {

        @Override
        public Sequence run(Query query, Map responseContext) {
            return new Sequence() {

                @Override
                public Object accumulate(Object initValue, Accumulator accumulator) {
                    throw new SegmentMissingException("FAILSAUCE");
                }

                @Override
                public Yielder<Object> toYielder(Object initValue, YieldingAccumulator accumulator) {
                    throw new SegmentMissingException("FAILSAUCE");
                }
            };
        }
    }, new SpecificSegmentSpec(descriptor));
    // from accumulate
    Map<String, Object> responseContext = Maps.newHashMap();
    TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("foo").granularity(Granularities.ALL).intervals(ImmutableList.of(new Interval("2012-01-01T00:00:00Z/P1D"))).aggregators(ImmutableList.<AggregatorFactory>of(new CountAggregatorFactory("rows"))).build();
    Sequence results = queryRunner.run(query, responseContext);
    Sequences.toList(results, Lists.newArrayList());
    validate(mapper, descriptor, responseContext);
    // from toYielder
    responseContext = Maps.newHashMap();
    results = queryRunner.run(query, responseContext);
    results.toYielder(null, new YieldingAccumulator() {

        final List lists = Lists.newArrayList();

        @Override
        public Object accumulate(Object accumulated, Object in) {
            lists.add(in);
            return in;
        }
    });
    validate(mapper, descriptor, responseContext);
}
Also used : Accumulator(io.druid.java.util.common.guava.Accumulator) YieldingAccumulator(io.druid.java.util.common.guava.YieldingAccumulator) Yielder(io.druid.java.util.common.guava.Yielder) TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) Query(io.druid.query.Query) TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) SegmentMissingException(io.druid.segment.SegmentMissingException) Sequence(io.druid.java.util.common.guava.Sequence) YieldingAccumulator(io.druid.java.util.common.guava.YieldingAccumulator) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) QueryRunner(io.druid.query.QueryRunner) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) SegmentDescriptor(io.druid.query.SegmentDescriptor) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Map(java.util.Map) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 23 with SegmentDescriptor

use of io.druid.query.SegmentDescriptor in project druid by druid-io.

the class SpecificSegmentQueryRunnerTest method testRetry2.

@SuppressWarnings("unchecked")
@Test
public void testRetry2() throws Exception {
    final ObjectMapper mapper = new DefaultObjectMapper();
    SegmentDescriptor descriptor = new SegmentDescriptor(new Interval("2012-01-01T00:00:00Z/P1D"), "version", 0);
    TimeseriesResultBuilder builder = new TimeseriesResultBuilder(new DateTime("2012-01-01T00:00:00Z"));
    CountAggregator rows = new CountAggregator();
    rows.aggregate();
    builder.addMetric("rows", rows);
    final Result<TimeseriesResultValue> value = builder.build();
    final SpecificSegmentQueryRunner queryRunner = new SpecificSegmentQueryRunner(new QueryRunner() {

        @Override
        public Sequence run(Query query, Map responseContext) {
            return Sequences.withEffect(Sequences.simple(Arrays.asList(value)), new Runnable() {

                @Override
                public void run() {
                    throw new SegmentMissingException("FAILSAUCE");
                }
            }, MoreExecutors.sameThreadExecutor());
        }
    }, new SpecificSegmentSpec(descriptor));
    final Map<String, Object> responseContext = Maps.newHashMap();
    TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("foo").granularity(Granularities.ALL).intervals(ImmutableList.of(new Interval("2012-01-01T00:00:00Z/P1D"))).aggregators(ImmutableList.<AggregatorFactory>of(new CountAggregatorFactory("rows"))).build();
    Sequence results = queryRunner.run(query, responseContext);
    List<Result<TimeseriesResultValue>> res = Sequences.toList(results, Lists.<Result<TimeseriesResultValue>>newArrayList());
    Assert.assertEquals(1, res.size());
    Result<TimeseriesResultValue> theVal = res.get(0);
    Assert.assertTrue(1L == theVal.getValue().getLongMetric("rows"));
    validate(mapper, descriptor, responseContext);
}
Also used : TimeseriesResultValue(io.druid.query.timeseries.TimeseriesResultValue) TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) Query(io.druid.query.Query) SegmentMissingException(io.druid.segment.SegmentMissingException) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) SegmentDescriptor(io.druid.query.SegmentDescriptor) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) TimeseriesResultBuilder(io.druid.query.timeseries.TimeseriesResultBuilder) Sequence(io.druid.java.util.common.guava.Sequence) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) QueryRunner(io.druid.query.QueryRunner) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) CountAggregator(io.druid.query.aggregation.CountAggregator) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Map(java.util.Map) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 24 with SegmentDescriptor

use of io.druid.query.SegmentDescriptor in project druid by druid-io.

the class SpecificSegmentQueryRunnerTest method validate.

private void validate(ObjectMapper mapper, SegmentDescriptor descriptor, Map<String, Object> responseContext) throws java.io.IOException {
    Object missingSegments = responseContext.get(Result.MISSING_SEGMENTS_KEY);
    Assert.assertTrue(missingSegments != null);
    Assert.assertTrue(missingSegments instanceof List);
    Object segmentDesc = ((List) missingSegments).get(0);
    Assert.assertTrue(segmentDesc instanceof SegmentDescriptor);
    SegmentDescriptor newDesc = mapper.readValue(mapper.writeValueAsString(segmentDesc), SegmentDescriptor.class);
    Assert.assertEquals(descriptor, newDesc);
}
Also used : SegmentDescriptor(io.druid.query.SegmentDescriptor) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 25 with SegmentDescriptor

use of io.druid.query.SegmentDescriptor in project druid by druid-io.

the class CoordinatorBasedSegmentHandoffNotifier method checkForSegmentHandoffs.

void checkForSegmentHandoffs() {
    try {
        Iterator<Map.Entry<SegmentDescriptor, Pair<Executor, Runnable>>> itr = handOffCallbacks.entrySet().iterator();
        while (itr.hasNext()) {
            Map.Entry<SegmentDescriptor, Pair<Executor, Runnable>> entry = itr.next();
            SegmentDescriptor descriptor = entry.getKey();
            try {
                List<ImmutableSegmentLoadInfo> loadedSegments = coordinatorClient.fetchServerView(dataSource, descriptor.getInterval(), true);
                if (isHandOffComplete(loadedSegments, entry.getKey())) {
                    log.info("Segment Handoff complete for dataSource[%s] Segment[%s]", dataSource, descriptor);
                    entry.getValue().lhs.execute(entry.getValue().rhs);
                    itr.remove();
                }
            } catch (Exception e) {
                log.error(e, "Exception while checking handoff for dataSource[%s] Segment[%s], Will try again after [%d]secs", dataSource, descriptor, pollDurationMillis);
            }
        }
        if (!handOffCallbacks.isEmpty()) {
            log.info("Still waiting for Handoff for Segments : [%s]", handOffCallbacks.keySet());
        }
    } catch (Throwable t) {
        log.error(t, "Exception while checking handoff for dataSource[%s] Segment[%s], Will try again after [%d]secs", dataSource, pollDurationMillis);
    }
}
Also used : Executor(java.util.concurrent.Executor) SegmentDescriptor(io.druid.query.SegmentDescriptor) ImmutableSegmentLoadInfo(io.druid.client.ImmutableSegmentLoadInfo) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) Pair(io.druid.java.util.common.Pair)

Aggregations

SegmentDescriptor (io.druid.query.SegmentDescriptor)48 Test (org.junit.Test)30 Interval (org.joda.time.Interval)19 TaskStatus (io.druid.indexing.common.TaskStatus)17 QueryRunner (io.druid.query.QueryRunner)12 Map (java.util.Map)11 Query (io.druid.query.Query)10 ImmutableMap (com.google.common.collect.ImmutableMap)8 Pair (io.druid.java.util.common.Pair)8 DataSegment (io.druid.timeline.DataSegment)8 Executor (java.util.concurrent.Executor)8 ImmutableSegmentLoadInfo (io.druid.client.ImmutableSegmentLoadInfo)7 TimeseriesQuery (io.druid.query.timeseries.TimeseriesQuery)7 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)6 IOException (java.io.IOException)6 List (java.util.List)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 Sequence (io.druid.java.util.common.guava.Sequence)5 SpecificSegmentQueryRunner (io.druid.query.spec.SpecificSegmentQueryRunner)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4