Search in sources :

Example 11 with Segment

use of io.druid.segment.Segment in project druid by druid-io.

the class QueryRunnerTestHelper method makeFilteringQueryRunner.

public static <T> QueryRunner<T> makeFilteringQueryRunner(final VersionedIntervalTimeline<String, Segment> timeline, final QueryRunnerFactory<T, Query<T>> factory) {
    final QueryToolChest<T, Query<T>> toolChest = factory.getToolchest();
    return new FluentQueryRunnerBuilder<T>(toolChest).create(new QueryRunner<T>() {

        @Override
        public Sequence<T> run(Query<T> query, Map<String, Object> responseContext) {
            List<TimelineObjectHolder> segments = Lists.newArrayList();
            for (Interval interval : query.getIntervals()) {
                segments.addAll(timeline.lookup(interval));
            }
            List<Sequence<T>> sequences = Lists.newArrayList();
            for (TimelineObjectHolder<String, Segment> holder : toolChest.filterSegments(query, segments)) {
                Segment segment = holder.getObject().getChunk(0).getObject();
                Query running = query.withQuerySegmentSpec(new SpecificSegmentSpec(new SegmentDescriptor(holder.getInterval(), holder.getVersion(), 0)));
                sequences.add(factory.createRunner(segment).run(running, responseContext));
            }
            return new MergeSequence<>(query.getResultOrdering(), Sequences.simple(sequences));
        }
    }).applyPreMergeDecoration().mergeResults().applyPostMergeDecoration();
}
Also used : TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) Sequence(io.druid.java.util.common.guava.Sequence) MergeSequence(io.druid.java.util.common.guava.MergeSequence) IncrementalIndexSegment(io.druid.segment.IncrementalIndexSegment) QueryableIndexSegment(io.druid.segment.QueryableIndexSegment) Segment(io.druid.segment.Segment) TimelineObjectHolder(io.druid.timeline.TimelineObjectHolder) SpecificSegmentSpec(io.druid.query.spec.SpecificSegmentSpec) MergeSequence(io.druid.java.util.common.guava.MergeSequence) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Interval(org.joda.time.Interval)

Aggregations

Segment (io.druid.segment.Segment)11 IncrementalIndexSegment (io.druid.segment.IncrementalIndexSegment)7 Interval (org.joda.time.Interval)7 DataSegment (io.druid.timeline.DataSegment)6 IncrementalIndex (io.druid.segment.incremental.IncrementalIndex)5 OnheapIncrementalIndex (io.druid.segment.incremental.OnheapIncrementalIndex)5 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)4 TimeseriesQuery (io.druid.query.timeseries.TimeseriesQuery)4 QueryableIndexSegment (io.druid.segment.QueryableIndexSegment)4 Test (org.junit.Test)4 FinalizeResultsQueryRunner (io.druid.query.FinalizeResultsQueryRunner)3 QueryRunnerFactory (io.druid.query.QueryRunnerFactory)3 Result (io.druid.query.Result)3 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)3 DoubleSumAggregatorFactory (io.druid.query.aggregation.DoubleSumAggregatorFactory)3 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)3 CharSource (com.google.common.io.CharSource)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2