Search in sources :

Example 1 with BitmapValues

use of org.apache.druid.segment.data.BitmapValues in project druid by druid-io.

the class DictionaryEncodedColumnMerger method mergeBitmaps.

protected MutableBitmap mergeBitmaps(@Nullable List<IntBuffer> segmentRowNumConversions, BitmapFactory bmpFactory, IndexSeeker[] dictIdSeeker, int dictId) throws IOException {
    List<IntIterable> convertedInvertedIndexesToMerge = Lists.newArrayListWithCapacity(adapters.size());
    for (int j = 0; j < adapters.size(); ++j) {
        int seekedDictId = dictIdSeeker[j].seek(dictId);
        if (seekedDictId != IndexSeeker.NOT_EXIST) {
            IntIterable values;
            if (segmentRowNumConversions != null) {
                values = new ConvertingBitmapValues(adapters.get(j).getBitmapValues(dimensionName, seekedDictId), segmentRowNumConversions.get(j));
            } else {
                BitmapValues bitmapValues = adapters.get(j).getBitmapValues(dimensionName, seekedDictId);
                values = bitmapValues::iterator;
            }
            convertedInvertedIndexesToMerge.add(values);
        }
    }
    MutableBitmap mergedIndexes = bmpFactory.makeEmptyMutableBitmap();
    List<IntIterator> convertedInvertedIndexesIterators = new ArrayList<>(convertedInvertedIndexesToMerge.size());
    for (IntIterable convertedInvertedIndexes : convertedInvertedIndexesToMerge) {
        convertedInvertedIndexesIterators.add(convertedInvertedIndexes.iterator());
    }
    // Merge ascending index iterators into a single one, remove duplicates, and add to the mergedIndexes bitmap.
    // Merge is needed, because some compacting MutableBitmap implementations are very inefficient when bits are
    // added not in the ascending order.
    int prevRow = IndexMerger.INVALID_ROW;
    for (IntIterator mergeIt = IntIteratorUtils.mergeAscending(convertedInvertedIndexesIterators); mergeIt.hasNext(); ) {
        int row = mergeIt.nextInt();
        if (row != prevRow && row != IndexMerger.INVALID_ROW) {
            mergedIndexes.add(row);
        }
        prevRow = row;
    }
    if (dictId == 0 && firstDictionaryValue == null) {
        mergedIndexes.or(nullRowsBitmap);
    }
    bitmapWriter.write(bmpFactory.makeImmutableBitmap(mergedIndexes));
    return mergedIndexes;
}
Also used : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) ArrayList(java.util.ArrayList) BitmapValues(org.apache.druid.segment.data.BitmapValues) IntIterable(it.unimi.dsi.fastutil.ints.IntIterable)

Example 2 with BitmapValues

use of org.apache.druid.segment.data.BitmapValues in project druid by druid-io.

the class IncrementalIndexAdapterTest method testGetBitmapIndex.

@Test
public void testGetBitmapIndex() throws Exception {
    final long timestamp = System.currentTimeMillis();
    IncrementalIndex incrementalIndex = indexCreator.createIndex("rollup");
    IncrementalIndexTest.populateIndex(timestamp, incrementalIndex);
    IndexableAdapter adapter = new IncrementalIndexAdapter(incrementalIndex.getInterval(), incrementalIndex, INDEX_SPEC.getBitmapSerdeFactory().getBitmapFactory());
    String dimension = "dim1";
    try (CloseableIndexed<String> dimValueLookup = adapter.getDimValueLookup(dimension)) {
        for (int i = 0; i < dimValueLookup.size(); i++) {
            BitmapValues bitmapValues = adapter.getBitmapValues(dimension, i);
            Assert.assertEquals(1, bitmapValues.size());
        }
    }
}
Also used : IndexableAdapter(org.apache.druid.segment.IndexableAdapter) BitmapValues(org.apache.druid.segment.data.BitmapValues) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) IncrementalIndexTest(org.apache.druid.segment.data.IncrementalIndexTest)

Example 3 with BitmapValues

use of org.apache.druid.segment.data.BitmapValues in project druid by druid-io.

the class QueryableIndexIndexableAdapterTest method testGetBitmapIndex.

@Test
public void testGetBitmapIndex() throws Exception {
    final long timestamp = System.currentTimeMillis();
    IncrementalIndex toPersist = IncrementalIndexTest.createIndex(null);
    IncrementalIndexTest.populateIndex(timestamp, toPersist);
    final File tempDir = temporaryFolder.newFolder();
    QueryableIndex index = closer.closeLater(indexIO.loadIndex(indexMerger.persist(toPersist, tempDir, INDEX_SPEC, null)));
    IndexableAdapter adapter = new QueryableIndexIndexableAdapter(index);
    String dimension = "dim1";
    // null is added to all dimensions with value
    @SuppressWarnings("UnusedAssignment") BitmapValues bitmapValues = adapter.getBitmapValues(dimension, 0);
    try (CloseableIndexed<String> dimValueLookup = adapter.getDimValueLookup(dimension)) {
        for (int i = 0; i < dimValueLookup.size(); i++) {
            bitmapValues = adapter.getBitmapValues(dimension, i);
            Assert.assertEquals(1, bitmapValues.size());
        }
    }
}
Also used : IncrementalIndex(org.apache.druid.segment.incremental.IncrementalIndex) BitmapValues(org.apache.druid.segment.data.BitmapValues) File(java.io.File) Test(org.junit.Test) IncrementalIndexTest(org.apache.druid.segment.data.IncrementalIndexTest)

Aggregations

BitmapValues (org.apache.druid.segment.data.BitmapValues)3 IncrementalIndexTest (org.apache.druid.segment.data.IncrementalIndexTest)2 Test (org.junit.Test)2 IntIterable (it.unimi.dsi.fastutil.ints.IntIterable)1 IntIterator (it.unimi.dsi.fastutil.ints.IntIterator)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 MutableBitmap (org.apache.druid.collections.bitmap.MutableBitmap)1 IndexableAdapter (org.apache.druid.segment.IndexableAdapter)1 IncrementalIndex (org.apache.druid.segment.incremental.IncrementalIndex)1 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)1