Search in sources :

Example 1 with WrappedImmutableConciseBitmap

use of org.apache.druid.collections.bitmap.WrappedImmutableConciseBitmap 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 2 with WrappedImmutableConciseBitmap

use of org.apache.druid.collections.bitmap.WrappedImmutableConciseBitmap 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 3 with WrappedImmutableConciseBitmap

use of org.apache.druid.collections.bitmap.WrappedImmutableConciseBitmap in project druid by druid-io.

the class VectorSelectorUtilsTest method testConciseImmutableNullVector.

@Test
public void testConciseImmutableNullVector() {
    final WrappedConciseBitmap bitmap = new WrappedConciseBitmap();
    populate(bitmap, NULLS);
    final ImmutableBitmap immutable = new WrappedImmutableConciseBitmap(ImmutableConciseSet.newImmutableFromMutable(bitmap.getBitmap()));
    assertNullVector(immutable, NULLS);
    final WrappedConciseBitmap bitmap2 = new WrappedConciseBitmap();
    populate(bitmap2, NULLS_PATTERN);
    final ImmutableBitmap immutable2 = new WrappedImmutableConciseBitmap(ImmutableConciseSet.newImmutableFromMutable(bitmap2.getBitmap()));
    assertNullVector(immutable2, NULLS_PATTERN);
}
Also used : WrappedConciseBitmap(org.apache.druid.collections.bitmap.WrappedConciseBitmap) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) WrappedImmutableConciseBitmap(org.apache.druid.collections.bitmap.WrappedImmutableConciseBitmap) Test(org.junit.Test)

Aggregations

WrappedImmutableConciseBitmap (org.apache.druid.collections.bitmap.WrappedImmutableConciseBitmap)3 WrappedImmutableRoaringBitmap (org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap)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 ImmutableBitmap (org.apache.druid.collections.bitmap.ImmutableBitmap)1 WrappedConciseBitmap (org.apache.druid.collections.bitmap.WrappedConciseBitmap)1 ConciseSet (org.apache.druid.extendedset.intset.ConciseSet)1 IAE (org.apache.druid.java.util.common.IAE)1 Test (org.junit.Test)1 Setup (org.openjdk.jmh.annotations.Setup)1 ImmutableRoaringBitmap (org.roaringbitmap.buffer.ImmutableRoaringBitmap)1 MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)1