Search in sources :

Example 1 with IntIterable

use of it.unimi.dsi.fastutil.ints.IntIterable 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)

Aggregations

IntIterable (it.unimi.dsi.fastutil.ints.IntIterable)1 IntIterator (it.unimi.dsi.fastutil.ints.IntIterator)1 ArrayList (java.util.ArrayList)1 MutableBitmap (org.apache.druid.collections.bitmap.MutableBitmap)1 BitmapValues (org.apache.druid.segment.data.BitmapValues)1