use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class RangeBitmapBenchmark method setup.
@Setup(Level.Trial)
public void setup() throws IOException {
switch(type) {
case "concise":
bitmapFactory = new ConciseBitmapFactory();
break;
case "roaring":
bitmapFactory = new RoaringBitmapFactory();
break;
default:
throw new IAE("Unknown bitmap type[%s]", type);
}
bitmaps = new ArrayList<>(numBitmaps);
for (int i = 0; i < numBitmaps; ++i) {
final MutableBitmap mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
int k = 0;
boolean fill = true;
while (k < bitmapLength) {
int runLength = (int) (bitmapLength * density) + RANDOM.nextInt((int) (bitmapLength * density));
for (int j = k; fill && j < bitmapLength && j < k + runLength; ++j) {
mutableBitmap.add(j);
}
k += runLength;
fill = !fill;
}
for (k = bitmapLength / 2; k < bitmapLength / 2 + minIntersect; ++k) {
mutableBitmap.add(k);
}
bitmaps.add(BitmapBenchmarkUtils.toOffheap(bitmapFactory.makeImmutableBitmap(mutableBitmap)));
}
final long totalSizeBytes = bitmaps.stream().mapToLong(bitmap -> bitmap.toBytes().length).sum();
BitmapBenchmarkUtils.printSizeStats(type, density, bitmaps.size(), totalSizeBytes);
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class DistinctCountBufferAggregator method getMutableBitmap.
private MutableBitmap getMutableBitmap(int position) {
MutableBitmap mutableBitmap = mutableBitmapCollection.get(position);
if (mutableBitmap == null) {
mutableBitmap = new WrappedRoaringBitmap();
mutableBitmapCollection.put(position, mutableBitmap);
}
return mutableBitmap;
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class DistinctCountBufferAggregator method aggregate.
@Override
public void aggregate(ByteBuffer buf, int position) {
MutableBitmap mutableBitmap = getMutableBitmap(position);
IndexedInts row = selector.getRow();
for (int i = 0, rowSize = row.size(); i < rowSize; i++) {
int index = row.get(i);
mutableBitmap.add(index);
}
buf.putLong(position, mutableBitmap.size());
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class UseIndexesStrategy method makeTimeFilteredBitmap.
static ImmutableBitmap makeTimeFilteredBitmap(final QueryableIndex index, final Segment segment, final Filter filter, final Interval interval) {
final BitmapFactory bitmapFactory = index.getBitmapFactoryForDimensions();
final ImmutableBitmap baseFilter;
if (filter == null) {
baseFilter = null;
} else {
final BitmapIndexSelector selector = new ColumnSelectorBitmapIndexSelector(index.getBitmapFactoryForDimensions(), VirtualColumns.EMPTY, index);
Preconditions.checkArgument(filter.supportsBitmapIndex(selector), "filter[%s] should support bitmap", filter);
baseFilter = filter.getBitmapIndex(selector);
}
final ImmutableBitmap timeFilteredBitmap;
if (!interval.contains(segment.getDataInterval())) {
final MutableBitmap timeBitmap = bitmapFactory.makeEmptyMutableBitmap();
final ColumnHolder timeColumnHolder = index.getColumnHolder(ColumnHolder.TIME_COLUMN_NAME);
try (final NumericColumn timeValues = (NumericColumn) timeColumnHolder.getColumn()) {
int startIndex = Math.max(0, getStartIndexOfTime(timeValues, interval.getStartMillis(), true));
int endIndex = Math.min(timeValues.length() - 1, getStartIndexOfTime(timeValues, interval.getEndMillis(), false));
for (int i = startIndex; i <= endIndex; i++) {
timeBitmap.add(i);
}
final ImmutableBitmap finalTimeBitmap = bitmapFactory.makeImmutableBitmap(timeBitmap);
timeFilteredBitmap = (baseFilter == null) ? finalTimeBitmap : finalTimeBitmap.intersection(baseFilter);
}
} else {
timeFilteredBitmap = baseFilter;
}
return timeFilteredBitmap;
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class TestIntegerSet method testRemoveEverything.
@Test
public void testRemoveEverything() 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 = IntSetTestUtility.getSetBits();
integerSet.removeAll(set);
boolean isEmpty = integerSet.isEmpty();
Assert.assertTrue(isEmpty);
}
}
Aggregations