Search in sources :

Example 1 with ConciseSet

use of org.apache.druid.extendedset.intset.ConciseSet in project druid by druid-io.

the class BitmapOperationAgainstConsecutiveRunsTest method prepareRandomRanges.

@BeforeClass
public static void prepareRandomRanges() throws Exception {
    reset();
    final BitSet expectedUnion = new BitSet();
    for (int i = 0; i < NUM_BITMAPS; ++i) {
        ConciseSet c = new ConciseSet();
        MutableRoaringBitmap r = new MutableRoaringBitmap();
        {
            int k = 0;
            boolean fill = true;
            while (k < BITMAP_LENGTH) {
                int runLength = (int) (BITMAP_LENGTH * DENSITY) + rand.nextInt((int) (BITMAP_LENGTH * DENSITY));
                for (int j = k; fill && j < BITMAP_LENGTH && j < k + runLength; ++j) {
                    c.add(j);
                    r.add(j);
                    expectedUnion.set(j);
                }
                k += runLength;
                fill = !fill;
            }
        }
        minIntersection = MIN_INTERSECT;
        for (int k = BITMAP_LENGTH / 2; k < BITMAP_LENGTH / 2 + minIntersection; ++k) {
            c.add(k);
            r.add(k);
            expectedUnion.set(k);
        }
        CONCISE[i] = ImmutableConciseSet.newImmutableFromMutable(c);
        OFF_HEAP_CONCISE[i] = makeOffheapConcise(CONCISE[i]);
        ROARING[i] = r;
        IMMUTABLE_ROARING[i] = makeImmutableRoaring(r);
        OFF_HEAP_ROARING[i] = makeOffheapRoaring(r);
        GENERIC_CONCISE[i] = new WrappedImmutableConciseBitmap(OFF_HEAP_CONCISE[i]);
        GENERIC_ROARING[i] = new WrappedImmutableRoaringBitmap(OFF_HEAP_ROARING[i]);
    }
    unionCount = expectedUnion.cardinality();
    printSizeStats(DENSITY, "Random Alternating Bitmap");
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) ImmutableConciseSet(org.apache.druid.extendedset.intset.ImmutableConciseSet) ConciseSet(org.apache.druid.extendedset.intset.ConciseSet) BitSet(java.util.BitSet) BeforeClass(org.junit.BeforeClass)

Example 2 with ConciseSet

use of org.apache.druid.extendedset.intset.ConciseSet in project druid by druid-io.

the class BitmapOperationAgainstUniformDistributionTest method prepareMostlyUniform.

@BeforeClass
public static void prepareMostlyUniform() throws Exception {
    reset();
    final BitSet expectedUnion = new BitSet();
    final int[] knownTrue = new int[MIN_INTERSECT];
    for (int i = 0; i < knownTrue.length; ++i) {
        knownTrue[i] = rand.nextInt(BITMAP_LENGTH);
    }
    for (int i = 0; i < NUM_BITMAPS; ++i) {
        ConciseSet c = new ConciseSet();
        MutableRoaringBitmap r = new MutableRoaringBitmap();
        for (int k = 0; k < BITMAP_LENGTH; ++k) {
            if (rand.nextDouble() < DENSITY) {
                c.add(k);
                r.add(k);
                expectedUnion.set(k);
            }
        }
        for (int k : knownTrue) {
            c.add(k);
            r.add(k);
            expectedUnion.set(k);
        }
        CONCISE[i] = ImmutableConciseSet.newImmutableFromMutable(c);
        OFF_HEAP_CONCISE[i] = makeOffheapConcise(CONCISE[i]);
        ROARING[i] = r;
        IMMUTABLE_ROARING[i] = makeImmutableRoaring(r);
        OFF_HEAP_ROARING[i] = makeOffheapRoaring(r);
        GENERIC_CONCISE[i] = new WrappedImmutableConciseBitmap(OFF_HEAP_CONCISE[i]);
        GENERIC_ROARING[i] = new WrappedImmutableRoaringBitmap(OFF_HEAP_ROARING[i]);
    }
    unionCount = expectedUnion.cardinality();
    minIntersection = knownTrue.length;
    printSizeStats(DENSITY, "Uniform Bitmap");
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) ImmutableConciseSet(org.apache.druid.extendedset.intset.ImmutableConciseSet) ConciseSet(org.apache.druid.extendedset.intset.ConciseSet) BitSet(java.util.BitSet) BeforeClass(org.junit.BeforeClass)

Example 3 with ConciseSet

use of org.apache.druid.extendedset.intset.ConciseSet 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 4 with ConciseSet

use of org.apache.druid.extendedset.intset.ConciseSet in project druid by druid-io.

the class ConciseBitmapFactoryTest method testGetOutOfBounds.

@Test
public void testGetOutOfBounds() {
    final ConciseSet conciseSet = new ConciseSet();
    final Set<Integer> ints = ImmutableSet.of(0, 4, 9);
    for (int i : ints) {
        conciseSet.add(i);
    }
    final ImmutableBitmap immutableBitmap = new WrappedImmutableConciseBitmap(ImmutableConciseSet.newImmutableFromMutable(conciseSet));
    final MutableBitmap mutableBitmap = new WrappedConciseBitmap(conciseSet);
    for (int i = 0; i < 10; ++i) {
        Assert.assertEquals(Integer.toString(i), ints.contains(i), mutableBitmap.get(i));
        Assert.assertEquals(Integer.toString(i), ints.contains(i), immutableBitmap.get(i));
    }
}
Also used : ImmutableConciseSet(org.apache.druid.extendedset.intset.ImmutableConciseSet) ConciseSet(org.apache.druid.extendedset.intset.ConciseSet) Test(org.junit.Test)

Example 5 with ConciseSet

use of org.apache.druid.extendedset.intset.ConciseSet in project druid by druid-io.

the class WrappedConciseBitmap method or.

@Override
public void or(MutableBitmap mutableBitmap) {
    WrappedConciseBitmap other = (WrappedConciseBitmap) mutableBitmap;
    ConciseSet unwrappedOtherBitmap = other.bitmap;
    bitmap.addAll(unwrappedOtherBitmap);
}
Also used : ImmutableConciseSet(org.apache.druid.extendedset.intset.ImmutableConciseSet) ConciseSet(org.apache.druid.extendedset.intset.ConciseSet)

Aggregations

ConciseSet (org.apache.druid.extendedset.intset.ConciseSet)6 ImmutableConciseSet (org.apache.druid.extendedset.intset.ImmutableConciseSet)6 BitSet (java.util.BitSet)3 MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)3 BeforeClass (org.junit.BeforeClass)2 WrappedImmutableConciseBitmap (org.apache.druid.collections.bitmap.WrappedImmutableConciseBitmap)1 WrappedImmutableRoaringBitmap (org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap)1 Test (org.junit.Test)1 Setup (org.openjdk.jmh.annotations.Setup)1