Search in sources :

Example 1 with PartitionHolder

use of io.druid.timeline.partition.PartitionHolder in project druid by druid-io.

the class ServerManager method getQueryRunnerForSegments.

@Override
public <T> QueryRunner<T> getQueryRunnerForSegments(Query<T> query, Iterable<SegmentDescriptor> specs) {
    final QueryRunnerFactory<T, Query<T>> factory = conglomerate.findFactory(query);
    if (factory == null) {
        log.makeAlert("Unknown query type, [%s]", query.getClass()).addData("dataSource", query.getDataSource()).emit();
        return new NoopQueryRunner<T>();
    }
    final QueryToolChest<T, Query<T>> toolChest = factory.getToolchest();
    String dataSourceName = getDataSourceName(query.getDataSource());
    final VersionedIntervalTimeline<String, ReferenceCountingSegment> timeline = dataSources.get(dataSourceName);
    if (timeline == null) {
        return new NoopQueryRunner<T>();
    }
    final Function<Query<T>, ServiceMetricEvent.Builder> builderFn = getBuilderFn(toolChest);
    final AtomicLong cpuTimeAccumulator = new AtomicLong(0L);
    FunctionalIterable<QueryRunner<T>> queryRunners = FunctionalIterable.create(specs).transformCat(new Function<SegmentDescriptor, Iterable<QueryRunner<T>>>() {

        @Override
        @SuppressWarnings("unchecked")
        public Iterable<QueryRunner<T>> apply(SegmentDescriptor input) {
            final PartitionHolder<ReferenceCountingSegment> entry = timeline.findEntry(input.getInterval(), input.getVersion());
            if (entry == null) {
                return Arrays.<QueryRunner<T>>asList(new ReportTimelineMissingSegmentQueryRunner<T>(input));
            }
            final PartitionChunk<ReferenceCountingSegment> chunk = entry.getChunk(input.getPartitionNumber());
            if (chunk == null) {
                return Arrays.<QueryRunner<T>>asList(new ReportTimelineMissingSegmentQueryRunner<T>(input));
            }
            final ReferenceCountingSegment adapter = chunk.getObject();
            return Arrays.asList(buildAndDecorateQueryRunner(factory, toolChest, adapter, input, builderFn, cpuTimeAccumulator));
        }
    });
    return CPUTimeMetricQueryRunner.safeBuild(new FinalizeResultsQueryRunner<>(toolChest.mergeResults(factory.mergeRunners(exec, queryRunners)), toolChest), builderFn, emitter, cpuTimeAccumulator, true);
}
Also used : ReferenceCountingSegment(io.druid.segment.ReferenceCountingSegment) PartitionHolder(io.druid.timeline.partition.PartitionHolder) Query(io.druid.query.Query) FunctionalIterable(io.druid.java.util.common.guava.FunctionalIterable) MetricsEmittingQueryRunner(io.druid.query.MetricsEmittingQueryRunner) ReportTimelineMissingSegmentQueryRunner(io.druid.query.ReportTimelineMissingSegmentQueryRunner) BySegmentQueryRunner(io.druid.query.BySegmentQueryRunner) SpecificSegmentQueryRunner(io.druid.query.spec.SpecificSegmentQueryRunner) ReferenceCountingSegmentQueryRunner(io.druid.query.ReferenceCountingSegmentQueryRunner) FinalizeResultsQueryRunner(io.druid.query.FinalizeResultsQueryRunner) CPUTimeMetricQueryRunner(io.druid.query.CPUTimeMetricQueryRunner) NoopQueryRunner(io.druid.query.NoopQueryRunner) CachingQueryRunner(io.druid.client.CachingQueryRunner) QueryRunner(io.druid.query.QueryRunner) AtomicLong(java.util.concurrent.atomic.AtomicLong) ReportTimelineMissingSegmentQueryRunner(io.druid.query.ReportTimelineMissingSegmentQueryRunner) NoopQueryRunner(io.druid.query.NoopQueryRunner) SegmentDescriptor(io.druid.query.SegmentDescriptor) PartitionChunk(io.druid.timeline.partition.PartitionChunk)

Example 2 with PartitionHolder

use of io.druid.timeline.partition.PartitionHolder in project druid by druid-io.

the class VersionedIntervalTimeline method lookup.

private List<TimelineObjectHolder<VersionType, ObjectType>> lookup(Interval interval, boolean incompleteOk) {
    List<TimelineObjectHolder<VersionType, ObjectType>> retVal = new ArrayList<TimelineObjectHolder<VersionType, ObjectType>>();
    NavigableMap<Interval, TimelineEntry> timeline = (incompleteOk) ? incompletePartitionsTimeline : completePartitionsTimeline;
    for (Map.Entry<Interval, TimelineEntry> entry : timeline.entrySet()) {
        Interval timelineInterval = entry.getKey();
        TimelineEntry val = entry.getValue();
        if (timelineInterval.overlaps(interval)) {
            retVal.add(new TimelineObjectHolder<VersionType, ObjectType>(timelineInterval, val.getVersion(), new PartitionHolder<ObjectType>(val.getPartitionHolder())));
        }
    }
    if (retVal.isEmpty()) {
        return retVal;
    }
    TimelineObjectHolder<VersionType, ObjectType> firstEntry = retVal.get(0);
    if (interval.overlaps(firstEntry.getInterval()) && interval.getStart().isAfter(firstEntry.getInterval().getStart())) {
        retVal.set(0, new TimelineObjectHolder<VersionType, ObjectType>(new Interval(interval.getStart(), firstEntry.getInterval().getEnd()), firstEntry.getVersion(), firstEntry.getObject()));
    }
    TimelineObjectHolder<VersionType, ObjectType> lastEntry = retVal.get(retVal.size() - 1);
    if (interval.overlaps(lastEntry.getInterval()) && interval.getEnd().isBefore(lastEntry.getInterval().getEnd())) {
        retVal.set(retVal.size() - 1, new TimelineObjectHolder<VersionType, ObjectType>(new Interval(lastEntry.getInterval().getStart(), interval.getEnd()), lastEntry.getVersion(), lastEntry.getObject()));
    }
    return retVal;
}
Also used : PartitionHolder(io.druid.timeline.partition.PartitionHolder) ImmutablePartitionHolder(io.druid.timeline.partition.ImmutablePartitionHolder) ArrayList(java.util.ArrayList) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Interval(org.joda.time.Interval)

Aggregations

PartitionHolder (io.druid.timeline.partition.PartitionHolder)2 CachingQueryRunner (io.druid.client.CachingQueryRunner)1 FunctionalIterable (io.druid.java.util.common.guava.FunctionalIterable)1 BySegmentQueryRunner (io.druid.query.BySegmentQueryRunner)1 CPUTimeMetricQueryRunner (io.druid.query.CPUTimeMetricQueryRunner)1 FinalizeResultsQueryRunner (io.druid.query.FinalizeResultsQueryRunner)1 MetricsEmittingQueryRunner (io.druid.query.MetricsEmittingQueryRunner)1 NoopQueryRunner (io.druid.query.NoopQueryRunner)1 Query (io.druid.query.Query)1 QueryRunner (io.druid.query.QueryRunner)1 ReferenceCountingSegmentQueryRunner (io.druid.query.ReferenceCountingSegmentQueryRunner)1 ReportTimelineMissingSegmentQueryRunner (io.druid.query.ReportTimelineMissingSegmentQueryRunner)1 SegmentDescriptor (io.druid.query.SegmentDescriptor)1 SpecificSegmentQueryRunner (io.druid.query.spec.SpecificSegmentQueryRunner)1 ReferenceCountingSegment (io.druid.segment.ReferenceCountingSegment)1 ImmutablePartitionHolder (io.druid.timeline.partition.ImmutablePartitionHolder)1 PartitionChunk (io.druid.timeline.partition.PartitionChunk)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1