Search in sources :

Example 1 with IndexableAdapter

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

the class IncrementalIndexAdapterTest method testGetBitmapIndex.

@Test
public void testGetBitmapIndex() throws Exception {
    final long timestamp = System.currentTimeMillis();
    IncrementalIndex incrementalIndex = IncrementalIndexTest.createIndex(null);
    IncrementalIndexTest.populateIndex(timestamp, incrementalIndex);
    IndexableAdapter adapter = new IncrementalIndexAdapter(incrementalIndex.getInterval(), incrementalIndex, INDEX_SPEC.getBitmapSerdeFactory().getBitmapFactory());
    String dimension = "dim1";
    for (int i = 0; i < adapter.getDimValueLookup(dimension).size(); i++) {
        IndexedInts indexedInts = adapter.getBitmapIndex(dimension, i);
        Assert.assertEquals(1, indexedInts.size());
    }
}
Also used : IndexedInts(io.druid.segment.data.IndexedInts) IndexableAdapter(io.druid.segment.IndexableAdapter) IncrementalIndexTest(io.druid.segment.data.IncrementalIndexTest) Test(org.junit.Test)

Example 2 with IndexableAdapter

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

the class IncrementalIndexAdapterTest method testGetRowsIterable.

@Test
public void testGetRowsIterable() throws Exception {
    final long timestamp = System.currentTimeMillis();
    IncrementalIndex toPersist1 = IncrementalIndexTest.createIndex(null);
    IncrementalIndexTest.populateIndex(timestamp, toPersist1);
    final IndexableAdapter incrementalAdapter = new IncrementalIndexAdapter(toPersist1.getInterval(), toPersist1, INDEX_SPEC.getBitmapSerdeFactory().getBitmapFactory());
    Iterable<Rowboat> boats = incrementalAdapter.getRows();
    List<Rowboat> boatList = new ArrayList<>();
    for (Rowboat boat : boats) {
        boatList.add(boat);
    }
    Assert.assertEquals(2, boatList.size());
    Assert.assertEquals(0, boatList.get(0).getRowNum());
    Assert.assertEquals(1, boatList.get(1).getRowNum());
    /* Iterate through the Iterable a few times, check that boat row numbers are correct afterwards */
    boatList = new ArrayList<>();
    for (Rowboat boat : boats) {
        boatList.add(boat);
    }
    boatList = new ArrayList<>();
    for (Rowboat boat : boats) {
        boatList.add(boat);
    }
    boatList = new ArrayList<>();
    for (Rowboat boat : boats) {
        boatList.add(boat);
    }
    boatList = new ArrayList<>();
    for (Rowboat boat : boats) {
        boatList.add(boat);
    }
    Assert.assertEquals(2, boatList.size());
    Assert.assertEquals(0, boatList.get(0).getRowNum());
    Assert.assertEquals(1, boatList.get(1).getRowNum());
}
Also used : ArrayList(java.util.ArrayList) IndexableAdapter(io.druid.segment.IndexableAdapter) Rowboat(io.druid.segment.Rowboat) IncrementalIndexTest(io.druid.segment.data.IncrementalIndexTest) Test(org.junit.Test)

Example 3 with IndexableAdapter

use of io.druid.segment.IndexableAdapter 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

IndexableAdapter (io.druid.segment.IndexableAdapter)3 Rowboat (io.druid.segment.Rowboat)2 IncrementalIndexTest (io.druid.segment.data.IncrementalIndexTest)2 Test (org.junit.Test)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 IndexMerger (io.druid.segment.IndexMerger)1 QueryableIndexIndexableAdapter (io.druid.segment.QueryableIndexIndexableAdapter)1 RowboatFilteringIndexAdapter (io.druid.segment.RowboatFilteringIndexAdapter)1 IndexedInts (io.druid.segment.data.IndexedInts)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 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 Interval (org.joda.time.Interval)1