use of org.apache.druid.collections.bitmap.ImmutableBitmap in project druid by druid-io.
the class BitmapVectorOffsetTest method testNeverContiguous.
@Test
public void testNeverContiguous() {
MutableRoaringBitmap wrapped = new MutableRoaringBitmap();
for (int i = 0; i < ROWS; i++) {
if (i % 2 != 0) {
wrapped.add(i);
}
}
ImmutableBitmap bitmap = new WrappedImmutableRoaringBitmap(wrapped.toImmutableRoaringBitmap());
for (int startOffset = 0; startOffset < ROWS; startOffset++) {
BitmapVectorOffset offset = new BitmapVectorOffset(VECTOR_SIZE, bitmap, startOffset, ROWS);
while (!offset.isDone()) {
Assert.assertFalse(offset.isContiguous());
offset.advance();
}
}
}
use of org.apache.druid.collections.bitmap.ImmutableBitmap in project druid by druid-io.
the class BitmapVectorOffsetTest method testContiguous.
@Test
public void testContiguous() {
// every bit is set, start from every offset and ensure all batches are contiguous
MutableRoaringBitmap wrapped = new MutableRoaringBitmap();
for (int i = 0; i < ROWS; i++) {
wrapped.add(i);
}
ImmutableBitmap bitmap = new WrappedImmutableRoaringBitmap(wrapped.toImmutableRoaringBitmap());
for (int startOffset = 0; startOffset < ROWS; startOffset++) {
BitmapVectorOffset offset = new BitmapVectorOffset(VECTOR_SIZE, bitmap, startOffset, ROWS);
while (!offset.isDone()) {
if (offset.getCurrentVectorSize() > 1) {
Assert.assertTrue(offset.isContiguous());
}
offset.advance();
}
}
}
use of org.apache.druid.collections.bitmap.ImmutableBitmap 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.ImmutableBitmap in project druid by druid-io.
the class BitmapCreationBenchmark method testFromImmutableByteArray.
@BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 1000)
@Test
public void testFromImmutableByteArray() {
ImmutableBitmap immutableBitmap = factory.mapImmutableBitmap(baseByteBuffer);
Assert.assertEquals(NUM_BITS, immutableBitmap.size());
}
use of org.apache.druid.collections.bitmap.ImmutableBitmap in project druid by druid-io.
the class ImmutableRTreeTest method testToAndFromByteBufferRoaring.
@Test
public void testToAndFromByteBufferRoaring() {
BitmapFactory bf = new RoaringBitmapFactory();
RTree tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
tree.insert(new float[] { 0, 0 }, 1);
tree.insert(new float[] { 1, 1 }, 2);
tree.insert(new float[] { 2, 2 }, 3);
tree.insert(new float[] { 3, 3 }, 4);
tree.insert(new float[] { 4, 4 }, 5);
ImmutableRTree firstTree = ImmutableRTree.newImmutableFromMutable(tree);
ByteBuffer buffer = ByteBuffer.wrap(firstTree.toBytes());
ImmutableRTree secondTree = new ImmutableRTree(buffer, bf);
Iterable<ImmutableBitmap> points = secondTree.search(new RadiusBound(new float[] { 0, 0 }, 10));
ImmutableBitmap finalSet = bf.union(points);
Assert.assertTrue(finalSet.size() >= 5);
Set<Integer> expected = Sets.newHashSet(1, 2, 3, 4, 5);
IntIterator iter = finalSet.iterator();
while (iter.hasNext()) {
Assert.assertTrue(expected.contains(iter.next()));
}
}
Aggregations