use of org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap in project druid by druid-io.
the class BitmapVectorOffsetTest method testSometimesContiguous.
@Test
public void testSometimesContiguous() {
// this test is sort of vague
// set a lot of the rows so that there will be some contiguous and always at least 1 non-contiguous group
// (i imagine this is somewhat dependent on underlying bitmap iterator implementation)
MutableRoaringBitmap wrapped = new MutableRoaringBitmap();
for (int i = 0; i < ROWS - VECTOR_SIZE + 1; i++) {
int set = ThreadLocalRandom.current().nextInt(0, ROWS);
while (wrapped.contains(set)) {
set = ThreadLocalRandom.current().nextInt(0, ROWS);
}
wrapped.add(set);
}
ImmutableBitmap bitmap = new WrappedImmutableRoaringBitmap(wrapped.toImmutableRoaringBitmap());
int contiguousCount = 0;
int nonContiguousCount = 0;
int noContiguous = 0;
int allContiguous = 0;
for (int startOffset = 0; startOffset < ROWS; startOffset++) {
BitmapVectorOffset offset = new BitmapVectorOffset(VECTOR_SIZE, bitmap, startOffset, ROWS);
boolean none = true;
boolean all = true;
while (!offset.isDone()) {
if (offset.isContiguous()) {
contiguousCount++;
none = false;
} else {
nonContiguousCount++;
all = false;
}
offset.advance();
}
if (none) {
noContiguous++;
}
if (all) {
allContiguous++;
}
}
Assert.assertTrue(contiguousCount > 0);
Assert.assertTrue(nonContiguousCount > 0);
// depending on the distribution of set bits and starting offset, there are some which are never contiguous
Assert.assertTrue(noContiguous > 0);
Assert.assertEquals(0, allContiguous);
}
use of org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap in project druid by druid-io.
the class BitmapBenchmarkUtils method toOffheap.
public static ImmutableBitmap toOffheap(ImmutableBitmap bitmap) throws IOException {
if (bitmap instanceof WrappedImmutableConciseBitmap) {
final WrappedImmutableConciseBitmap conciseBitmap = (WrappedImmutableConciseBitmap) bitmap;
final byte[] bytes = conciseBitmap.getBitmap().toBytes();
final ByteBuffer buf = ByteBuffer.allocateDirect(bytes.length).put(bytes);
buf.rewind();
return new WrappedImmutableConciseBitmap(new ImmutableConciseSet(buf.asIntBuffer()));
} else if (bitmap instanceof WrappedImmutableRoaringBitmap) {
final WrappedImmutableRoaringBitmap roaringBitmap = (WrappedImmutableRoaringBitmap) bitmap;
final ByteArrayOutputStream out = new ByteArrayOutputStream();
roaringBitmap.getBitmap().serialize(new DataOutputStream(out));
final byte[] bytes = out.toByteArray();
final ByteBuffer buf = ByteBuffer.allocateDirect(bytes.length);
buf.put(bytes);
buf.rewind();
return new WrappedImmutableRoaringBitmap(new ImmutableRoaringBitmap(buf.asReadOnlyBuffer()));
} else {
throw new IAE("Unsupported bitmap type [%s]", bitmap.getClass().getSimpleName());
}
}
use of org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap in project druid by druid-io.
the class BaseColumnarLongsBenchmark method setupChunkyFilter.
private void setupChunkyFilter(int rows, int filteredRowCount, int chunkSize) {
MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
for (int count = 0; count < filteredRowCount; ) {
int chunkOffset = rand.nextInt(rows - chunkSize);
// Skip already selected rows if any
while (bitmap.contains(chunkOffset)) {
chunkOffset = rand.nextInt(rows - chunkSize);
}
int numAdded = 0;
for (; numAdded < chunkSize && count + numAdded < filteredRowCount; numAdded++) {
// break if we run into an existing contiguous section
if (bitmap.contains(numAdded)) {
break;
}
bitmap.add(chunkOffset + numAdded);
}
count += numAdded;
}
offset = BitmapOffset.of(new WrappedImmutableRoaringBitmap(bitmap.toImmutableRoaringBitmap()), false, rows);
vectorOffset = new BitmapVectorOffset(VECTOR_SIZE, new WrappedImmutableRoaringBitmap(bitmap.toImmutableRoaringBitmap()), 0, rows);
}
use of org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap in project druid by druid-io.
the class NullHandlingBitmapGetVsIteratorBenchmark method setup.
@Setup
public void setup() {
pretendFilterOffsets = new BitSet(numRows);
switch(bitmapType) {
case "concise":
ConciseSet conciseSet = new ConciseSet();
for (int i = 0; i < numRows; i++) {
double rando = ThreadLocalRandom.current().nextDouble(0.0, 1.0);
if (filterMatch == 1.0 || rando < filterMatch) {
pretendFilterOffsets.set(i);
}
if (rando < nullDensity) {
conciseSet.add(i);
}
}
bitmap = new WrappedImmutableConciseBitmap(ImmutableConciseSet.newImmutableFromMutable(conciseSet));
break;
case "roaring":
MutableRoaringBitmap roaringBitmap = new MutableRoaringBitmap();
for (int i = 0; i < numRows; i++) {
double rando = ThreadLocalRandom.current().nextDouble(0.0, 1.0);
if (filterMatch == 1.0 || rando < filterMatch) {
pretendFilterOffsets.set(i);
}
if (rando < nullDensity) {
roaringBitmap.add(i);
}
}
bitmap = new WrappedImmutableRoaringBitmap(roaringBitmap.toImmutableRoaringBitmap());
break;
}
}
use of org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap in project druid by druid-io.
the class BaseColumnarLongsBenchmark method setupRandomFilter.
private void setupRandomFilter(int rows, int filteredRowCount) {
MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
for (int i = 0; i < filteredRowCount; i++) {
int rowToAccess = rand.nextInt(rows);
// Skip already selected rows if any
while (bitmap.contains(rowToAccess)) {
rowToAccess = rand.nextInt(rows);
}
bitmap.add(rowToAccess);
}
offset = BitmapOffset.of(new WrappedImmutableRoaringBitmap(bitmap.toImmutableRoaringBitmap()), false, rows);
vectorOffset = new BitmapVectorOffset(VECTOR_SIZE, new WrappedImmutableRoaringBitmap(bitmap.toImmutableRoaringBitmap()), 0, rows);
}
Aggregations