Search in sources :

Example 1 with RowboatFilteringIndexAdapter

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

the class AppendTask method merge.

@Override
public File merge(final TaskToolbox toolbox, final Map<DataSegment, File> segments, final File outDir) throws Exception {
    VersionedIntervalTimeline<String, DataSegment> timeline = new VersionedIntervalTimeline<String, DataSegment>(Ordering.<String>natural().nullsFirst());
    for (DataSegment segment : segments.keySet()) {
        timeline.add(segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk(segment));
    }
    final Iterable<SegmentToMergeHolder> segmentsToMerge = Iterables.concat(Iterables.transform(timeline.lookup(new Interval("1000-01-01/3000-01-01")), new Function<TimelineObjectHolder<String, DataSegment>, Iterable<SegmentToMergeHolder>>() {

        @Override
        public Iterable<SegmentToMergeHolder> apply(final TimelineObjectHolder<String, DataSegment> input) {
            return Iterables.transform(input.getObject(), new Function<PartitionChunk<DataSegment>, SegmentToMergeHolder>() {

                @Nullable
                @Override
                public SegmentToMergeHolder apply(PartitionChunk<DataSegment> chunkInput) {
                    DataSegment segment = chunkInput.getObject();
                    return new SegmentToMergeHolder(segment, input.getInterval(), Preconditions.checkNotNull(segments.get(segment), "File for segment %s", segment.getIdentifier()));
                }
            });
        }
    }));
    List<IndexableAdapter> adapters = Lists.newArrayList();
    for (final SegmentToMergeHolder holder : segmentsToMerge) {
        adapters.add(new RowboatFilteringIndexAdapter(new QueryableIndexIndexableAdapter(toolbox.getIndexIO().loadIndex(holder.getFile())), new Predicate<Rowboat>() {

            @Override
            public boolean apply(Rowboat input) {
                return holder.getInterval().contains(input.getTimestamp());
            }
        }));
    }
    IndexMerger indexMerger = buildV9Directly ? toolbox.getIndexMergerV9() : toolbox.getIndexMerger();
    return indexMerger.append(adapters, aggregators == null ? null : aggregators.toArray(new AggregatorFactory[aggregators.size()]), outDir, indexSpec);
}
Also used : IndexMerger(io.druid.segment.IndexMerger) RowboatFilteringIndexAdapter(io.druid.segment.RowboatFilteringIndexAdapter) DataSegment(io.druid.timeline.DataSegment) Predicate(com.google.common.base.Predicate) Function(com.google.common.base.Function) QueryableIndexIndexableAdapter(io.druid.segment.QueryableIndexIndexableAdapter) TimelineObjectHolder(io.druid.timeline.TimelineObjectHolder) VersionedIntervalTimeline(io.druid.timeline.VersionedIntervalTimeline) IndexableAdapter(io.druid.segment.IndexableAdapter) QueryableIndexIndexableAdapter(io.druid.segment.QueryableIndexIndexableAdapter) PartitionChunk(io.druid.timeline.partition.PartitionChunk) Nullable(javax.annotation.Nullable) Rowboat(io.druid.segment.Rowboat) Interval(org.joda.time.Interval)

Aggregations

Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 IndexMerger (io.druid.segment.IndexMerger)1 IndexableAdapter (io.druid.segment.IndexableAdapter)1 QueryableIndexIndexableAdapter (io.druid.segment.QueryableIndexIndexableAdapter)1 Rowboat (io.druid.segment.Rowboat)1 RowboatFilteringIndexAdapter (io.druid.segment.RowboatFilteringIndexAdapter)1 DataSegment (io.druid.timeline.DataSegment)1 TimelineObjectHolder (io.druid.timeline.TimelineObjectHolder)1 VersionedIntervalTimeline (io.druid.timeline.VersionedIntervalTimeline)1 PartitionChunk (io.druid.timeline.partition.PartitionChunk)1 Nullable (javax.annotation.Nullable)1 Interval (org.joda.time.Interval)1