Search in sources :

Example 6 with WrappedImmutableRoaringBitmap

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);
}
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 7 with WrappedImmutableRoaringBitmap

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());
    }
}
Also used : ImmutableConciseSet(org.apache.druid.extendedset.intset.ImmutableConciseSet) WrappedImmutableConciseBitmap(org.apache.druid.collections.bitmap.WrappedImmutableConciseBitmap) DataOutputStream(java.io.DataOutputStream) WrappedImmutableRoaringBitmap(org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap) ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap) WrappedImmutableRoaringBitmap(org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAE(org.apache.druid.java.util.common.IAE) ByteBuffer(java.nio.ByteBuffer)

Example 8 with WrappedImmutableRoaringBitmap

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

Example 9 with WrappedImmutableRoaringBitmap

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;
    }
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) WrappedImmutableConciseBitmap(org.apache.druid.collections.bitmap.WrappedImmutableConciseBitmap) ImmutableConciseSet(org.apache.druid.extendedset.intset.ImmutableConciseSet) ConciseSet(org.apache.druid.extendedset.intset.ConciseSet) BitSet(java.util.BitSet) WrappedImmutableRoaringBitmap(org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap) Setup(org.openjdk.jmh.annotations.Setup)

Example 10 with WrappedImmutableRoaringBitmap

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

Aggregations

WrappedImmutableRoaringBitmap (org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap)11 MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)9 ImmutableBitmap (org.apache.druid.collections.bitmap.ImmutableBitmap)6 Test (org.junit.Test)5 BitmapVectorOffset (org.apache.druid.segment.vector.BitmapVectorOffset)3 WrappedImmutableConciseBitmap (org.apache.druid.collections.bitmap.WrappedImmutableConciseBitmap)2 ImmutableConciseSet (org.apache.druid.extendedset.intset.ImmutableConciseSet)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 BitSet (java.util.BitSet)1 MutableBitmap (org.apache.druid.collections.bitmap.MutableBitmap)1 ConciseSet (org.apache.druid.extendedset.intset.ConciseSet)1 EmptyIntIterator (org.apache.druid.extendedset.intset.EmptyIntIterator)1 IAE (org.apache.druid.java.util.common.IAE)1 Setup (org.openjdk.jmh.annotations.Setup)1 IntIterator (org.roaringbitmap.IntIterator)1 ImmutableRoaringBitmap (org.roaringbitmap.buffer.ImmutableRoaringBitmap)1