Search in sources :

Example 16 with ImmutableBitmap

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();
        }
    }
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) WrappedImmutableRoaringBitmap(org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap) Test(org.junit.Test)

Example 17 with ImmutableBitmap

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();
        }
    }
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) WrappedImmutableRoaringBitmap(org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap) Test(org.junit.Test)

Example 18 with ImmutableBitmap

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);
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) WrappedImmutableRoaringBitmap(org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap) Test(org.junit.Test)

Example 19 with ImmutableBitmap

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());
}
Also used : ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) Test(org.junit.Test) BenchmarkOptions(com.carrotsearch.junitbenchmarks.BenchmarkOptions)

Example 20 with ImmutableBitmap

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()));
    }
}
Also used : IntIterator(org.roaringbitmap.IntIterator) RadiusBound(org.apache.druid.collections.spatial.search.RadiusBound) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) BitmapFactory(org.apache.druid.collections.bitmap.BitmapFactory) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) LinearGutmanSplitStrategy(org.apache.druid.collections.spatial.split.LinearGutmanSplitStrategy) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ImmutableBitmap (org.apache.druid.collections.bitmap.ImmutableBitmap)64 Test (org.junit.Test)37 BitmapFactory (org.apache.druid.collections.bitmap.BitmapFactory)24 RoaringBitmapFactory (org.apache.druid.collections.bitmap.RoaringBitmapFactory)22 ConciseBitmapFactory (org.apache.druid.collections.bitmap.ConciseBitmapFactory)19 LinearGutmanSplitStrategy (org.apache.druid.collections.spatial.split.LinearGutmanSplitStrategy)18 IntIterator (org.roaringbitmap.IntIterator)17 Benchmark (org.openjdk.jmh.annotations.Benchmark)14 RadiusBound (org.apache.druid.collections.spatial.search.RadiusBound)13 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)13 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)13 Random (java.util.Random)12 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)12 BitmapIndex (org.apache.druid.segment.column.BitmapIndex)9 ArrayList (java.util.ArrayList)6 WrappedImmutableRoaringBitmap (org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap)6 Filter (org.apache.druid.query.filter.Filter)6 ColumnHolder (org.apache.druid.segment.column.ColumnHolder)6 MutableBitmap (org.apache.druid.collections.bitmap.MutableBitmap)5 MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)5