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;
}
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());
}
}
}
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());
}
}
}
Aggregations