use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class TestIntegerSet method testIntOverflow.
@Test
public void testIntOverflow() throws IllegalAccessException, InstantiationException {
for (Class<? extends MutableBitmap> clazz : clazzes) {
Exception e = null;
try {
MutableBitmap wrappedBitmap = clazz.newInstance();
IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits());
IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap);
integerSet.add(Integer.MAX_VALUE + 1);
} catch (IllegalArgumentException ex) {
e = ex;
}
Assert.assertNotNull(e);
}
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class TestIntegerSet method testToSmallArray.
@Test
public void testToSmallArray() throws IllegalAccessException, InstantiationException {
for (Class<? extends MutableBitmap> clazz : clazzes) {
MutableBitmap wrappedBitmap = clazz.newInstance();
IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits());
IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap);
Set<Integer> set = Sets.newHashSet((Integer[]) integerSet.toArray(new Integer[0]));
Assert.assertTrue(Sets.difference(integerSet, set).isEmpty());
}
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class FiltersTest method makeNonOverlappedBitmapIndexes.
private static BitmapIndex makeNonOverlappedBitmapIndexes(final int bitmapNum, final List<ImmutableBitmap> bitmaps) {
final BitmapIndex bitmapIndex = getBitmapIndex(bitmaps);
final BitmapFactory factory = bitmapIndex.getBitmapFactory();
for (int i = 0; i < bitmapNum; i++) {
final MutableBitmap mutableBitmap = factory.makeEmptyMutableBitmap();
for (int j = 0; j < 10; j++) {
mutableBitmap.add(i * 10 + j);
}
bitmaps.add(factory.makeImmutableBitmap(mutableBitmap));
}
return bitmapIndex;
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class BitmapOffsetTest method testSanity.
@Test
public void testSanity() {
MutableBitmap mutable = factory.makeEmptyMutableBitmap();
for (int val : TEST_VALS) {
mutable.add(val);
}
ImmutableBitmap bitmap = factory.makeImmutableBitmap(mutable);
final BitmapOffset offset = BitmapOffset.of(bitmap, descending, bitmap.size());
final int[] expected = descending ? TEST_VALS_FLIP : TEST_VALS;
int count = 0;
while (offset.withinBounds()) {
Assert.assertEquals(expected[count], offset.getOffset());
int cloneCount = count;
Offset clonedOffset = offset.clone();
while (clonedOffset.withinBounds()) {
Assert.assertEquals(expected[cloneCount], clonedOffset.getOffset());
++cloneCount;
clonedOffset.increment();
}
++count;
offset.increment();
}
Assert.assertEquals(count, expected.length);
}
use of org.apache.druid.collections.bitmap.MutableBitmap 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;
}
Aggregations