Search in sources :

Example 1 with WrappedImmutableRoaringBitmap

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

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

the class BitmapVectorOffsetTest method testNotContiguousGetStartOffsetIsExplode.

@Test
public void testNotContiguousGetStartOffsetIsExplode() {
    MutableRoaringBitmap wrapped = new MutableRoaringBitmap();
    for (int i = 0; i < ROWS; i++) {
        if (i % 2 != 0) {
            wrapped.add(i);
        }
    }
    ImmutableBitmap bitmap = new WrappedImmutableRoaringBitmap(wrapped.toImmutableRoaringBitmap());
    BitmapVectorOffset offset = new BitmapVectorOffset(VECTOR_SIZE, bitmap, 0, ROWS);
    expectedException.expect(UnsupportedOperationException.class);
    expectedException.expectMessage("not contiguous");
    offset.getStartOffset();
}
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 3 with WrappedImmutableRoaringBitmap

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

the class BitmapVectorOffsetTest method testContiguousGetOffsetsIsExplode.

@Test
public void testContiguousGetOffsetsIsExplode() {
    MutableRoaringBitmap wrapped = new MutableRoaringBitmap();
    for (int i = 0; i < ROWS; i++) {
        wrapped.add(i);
    }
    ImmutableBitmap bitmap = new WrappedImmutableRoaringBitmap(wrapped.toImmutableRoaringBitmap());
    BitmapVectorOffset offset = new BitmapVectorOffset(VECTOR_SIZE, bitmap, 0, ROWS);
    expectedException.expect(UnsupportedOperationException.class);
    expectedException.expectMessage("is contiguous");
    offset.getOffsets();
}
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 4 with WrappedImmutableRoaringBitmap

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

use of org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap 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)

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