Search in sources :

Example 11 with MutableBitmap

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

the class BitmapOffset method getReverseBitmapOffsetIterator.

static IntIterator getReverseBitmapOffsetIterator(ImmutableBitmap bitmapIndex) {
    ImmutableBitmap roaringBitmap = bitmapIndex;
    if (!(bitmapIndex instanceof WrappedImmutableRoaringBitmap)) {
        final MutableBitmap bitmap = ROARING_BITMAP_FACTORY.makeEmptyMutableBitmap();
        final IntIterator iterator = bitmapIndex.iterator();
        while (iterator.hasNext()) {
            bitmap.add(iterator.next());
        }
        roaringBitmap = ROARING_BITMAP_FACTORY.makeImmutableBitmap(bitmap);
    }
    return ((WrappedImmutableRoaringBitmap) roaringBitmap).getBitmap().getReverseIntIterator();
}
Also used : EmptyIntIterator(org.apache.druid.extendedset.intset.EmptyIntIterator) IntIterator(org.roaringbitmap.IntIterator) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) WrappedImmutableRoaringBitmap(org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap)

Example 12 with MutableBitmap

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

the class BitmapCreationBenchmark method testLinearAddition.

@BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 1000)
@Test
public void testLinearAddition() {
    MutableBitmap mutableBitmap = factory.makeEmptyMutableBitmap();
    for (int i = 0; i < NUM_BITS; ++i) {
        mutableBitmap.add(i);
    }
    Assert.assertEquals(NUM_BITS, mutableBitmap.size());
}
Also used : MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) Test(org.junit.Test) BenchmarkOptions(com.carrotsearch.junitbenchmarks.BenchmarkOptions)

Example 13 with MutableBitmap

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

the class Point method makeBitmap.

private static MutableBitmap makeBitmap(int entry, BitmapFactory bitmapFactory) {
    MutableBitmap retVal = bitmapFactory.makeEmptyMutableBitmap();
    retVal.add(entry);
    return retVal;
}
Also used : MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap)

Example 14 with MutableBitmap

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

the class BitmapBenchmarkWithVaryingOrder method setup.

@Setup(Level.Trial)
public void setup() throws IOException {
    switch(type) {
        case "concise":
            bitmapFactory = new ConciseBitmapFactory();
            break;
        case "roaring":
            bitmapFactory = new RoaringBitmapFactory();
            break;
        default:
            throw new IAE("Unknown bitmap type[%s]", type);
    }
    bitmaps = new ArrayList<>(numBitmaps);
    // Bitmaps usually have a short circuit to early return an empty bitmap if it finds no intersection
    // during an AND operation. We want to let them iterate all bitmaps instead, so add some bits that
    // will be set for all bitmaps we create.
    final int[] knownTrue = new int[minIntersect];
    for (int i = 0; i < knownTrue.length; ++i) {
        knownTrue[i] = RANDOM.nextInt(bitmapLength);
    }
    for (int i = 0; i < numBitmaps; ++i) {
        // the later the bitmap is created, the higher its density is.
        final int bitCount = (int) (i * 0.1);
        IntSet ints = new IntOpenHashSet(bitCount);
        for (int j = 0; j < bitCount; j++) {
            int offset;
            do {
                offset = RANDOM.nextInt(bitmapLength);
            } while (ints.contains(offset));
            ints.add(offset);
        }
        final MutableBitmap mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
        ints.iterator().forEachRemaining((IntConsumer) mutableBitmap::add);
        for (int k : knownTrue) {
            mutableBitmap.add(k);
        }
        bitmaps.add(BitmapBenchmarkUtils.toOffheap(bitmapFactory.makeImmutableBitmap(mutableBitmap)));
    }
    reverseBitmaps = Lists.reverse(bitmaps);
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) IntSet(it.unimi.dsi.fastutil.ints.IntSet) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) IAE(org.apache.druid.java.util.common.IAE) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) Setup(org.openjdk.jmh.annotations.Setup)

Example 15 with MutableBitmap

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

the class UniformBitmapBenchmark method setup.

@Setup(Level.Trial)
public void setup() throws IOException {
    final int[] knownTrue = new int[minIntersect];
    for (int i = 0; i < knownTrue.length; ++i) {
        knownTrue[i] = RANDOM.nextInt(bitmapLength);
    }
    switch(type) {
        case "concise":
            bitmapFactory = new ConciseBitmapFactory();
            break;
        case "roaring":
            bitmapFactory = new RoaringBitmapFactory();
            break;
        default:
            throw new IAE("Unknown bitmap type[%s]", type);
    }
    bitmaps = new ArrayList<>(numBitmaps);
    for (int i = 0; i < numBitmaps; ++i) {
        final MutableBitmap mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
        for (int k = 0; k < bitmapLength; ++k) {
            if (RANDOM.nextDouble() < density) {
                mutableBitmap.add(k);
            }
        }
        for (int k : knownTrue) {
            mutableBitmap.add(k);
        }
        bitmaps.add(BitmapBenchmarkUtils.toOffheap(bitmapFactory.makeImmutableBitmap(mutableBitmap)));
    }
    final long totalSizeBytes = bitmaps.stream().mapToLong(bitmap -> bitmap.toBytes().length).sum();
    BitmapBenchmarkUtils.printSizeStats(type, density, bitmaps.size(), totalSizeBytes);
}
Also used : BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Measurement(org.openjdk.jmh.annotations.Measurement) Blackhole(org.openjdk.jmh.infra.Blackhole) Scope(org.openjdk.jmh.annotations.Scope) Random(java.util.Random) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) Warmup(org.openjdk.jmh.annotations.Warmup) ArrayList(java.util.ArrayList) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) BitmapFactory(org.apache.druid.collections.bitmap.BitmapFactory) IAE(org.apache.druid.java.util.common.IAE) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) Setup(org.openjdk.jmh.annotations.Setup) Mode(org.openjdk.jmh.annotations.Mode) Param(org.openjdk.jmh.annotations.Param) IOException(java.io.IOException) State(org.openjdk.jmh.annotations.State) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) Benchmark(org.openjdk.jmh.annotations.Benchmark) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) NullHandling(org.apache.druid.common.config.NullHandling) Level(org.openjdk.jmh.annotations.Level) Fork(org.openjdk.jmh.annotations.Fork) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) IAE(org.apache.druid.java.util.common.IAE) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

MutableBitmap (org.apache.druid.collections.bitmap.MutableBitmap)33 Test (org.junit.Test)15 BitmapFactory (org.apache.druid.collections.bitmap.BitmapFactory)8 ImmutableBitmap (org.apache.druid.collections.bitmap.ImmutableBitmap)7 RoaringBitmapFactory (org.apache.druid.collections.bitmap.RoaringBitmapFactory)6 Setup (org.openjdk.jmh.annotations.Setup)6 ArrayList (java.util.ArrayList)4 ConciseBitmapFactory (org.apache.druid.collections.bitmap.ConciseBitmapFactory)4 BitmapIndex (org.apache.druid.segment.column.BitmapIndex)4 BitmapSerdeFactory (org.apache.druid.segment.data.BitmapSerdeFactory)4 Benchmark (org.openjdk.jmh.annotations.Benchmark)4 BenchmarkOptions (com.carrotsearch.junitbenchmarks.BenchmarkOptions)3 Function (com.google.common.base.Function)3 List (java.util.List)3 Random (java.util.Random)3 TimeUnit (java.util.concurrent.TimeUnit)3 NullHandling (org.apache.druid.common.config.NullHandling)3 IAE (org.apache.druid.java.util.common.IAE)3 RoaringBitmapSerdeFactory (org.apache.druid.segment.data.RoaringBitmapSerdeFactory)3 StringBitmapIndexColumnPartSupplier (org.apache.druid.segment.serde.StringBitmapIndexColumnPartSupplier)3