Search in sources :

Example 11 with ImmutableRoaringBitmap

use of org.roaringbitmap.buffer.ImmutableRoaringBitmap in project druid by druid-io.

the class WrappedImmutableRoaringBitmap method difference.

@Override
public ImmutableBitmap difference(ImmutableBitmap otherBitmap) {
    WrappedImmutableRoaringBitmap other = (WrappedImmutableRoaringBitmap) otherBitmap;
    ImmutableRoaringBitmap unwrappedOtherBitmap = other.bitmap;
    return new WrappedImmutableRoaringBitmap(ImmutableRoaringBitmap.andNot(bitmap, unwrappedOtherBitmap));
}
Also used : ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap)

Example 12 with ImmutableRoaringBitmap

use of org.roaringbitmap.buffer.ImmutableRoaringBitmap in project druid by druid-io.

the class WrappedImmutableRoaringBitmap method union.

@Override
public ImmutableBitmap union(ImmutableBitmap otherBitmap) {
    WrappedImmutableRoaringBitmap other = (WrappedImmutableRoaringBitmap) otherBitmap;
    ImmutableRoaringBitmap unwrappedOtherBitmap = other.bitmap;
    return new WrappedImmutableRoaringBitmap(ImmutableRoaringBitmap.or(bitmap, unwrappedOtherBitmap));
}
Also used : ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap)

Example 13 with ImmutableRoaringBitmap

use of org.roaringbitmap.buffer.ImmutableRoaringBitmap in project pinot by linkedin.

the class BitmapInvertedIndexReader method buildRoaringBitmapForIndex.

private synchronized ImmutableRoaringBitmap buildRoaringBitmapForIndex(final int index) {
    final int currentOffset = getOffset(index);
    final int nextOffset = getOffset(index + 1);
    final int bufferLength = nextOffset - currentOffset;
    // Slice the buffer appropriately for Roaring Bitmap
    ByteBuffer bb = buffer.toDirectByteBuffer(currentOffset, bufferLength);
    ImmutableRoaringBitmap immutableRoaringBitmap = null;
    try {
        immutableRoaringBitmap = new ImmutableRoaringBitmap(bb);
    } catch (Exception e) {
        LOGGER.error("Error creating immutableRoaringBitmap for dictionary id:{} currentOffset:{} bufferLength:{} slice position{} limit:{} file:{}", index, currentOffset, bufferLength, bb.position(), bb.limit(), file.getAbsolutePath());
    }
    return immutableRoaringBitmap;
}
Also used : ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException)

Example 14 with ImmutableRoaringBitmap

use of org.roaringbitmap.buffer.ImmutableRoaringBitmap in project pinot by linkedin.

the class BitmapInvertedIndexReader method getImmutable.

/**
   * {@inheritDoc}
   * @see InvertedIndexReader#getImmutable(int)
   */
@Override
public ImmutableRoaringBitmap getImmutable(int idx) {
    SoftReference<ImmutableRoaringBitmap>[] bitmapArrayReference = null;
    // Return the bitmap if it's still on heap
    if (bitmaps != null) {
        bitmapArrayReference = bitmaps.get();
        if (bitmapArrayReference != null) {
            SoftReference<ImmutableRoaringBitmap> bitmapReference = bitmapArrayReference[idx];
            if (bitmapReference != null) {
                ImmutableRoaringBitmap value = bitmapReference.get();
                if (value != null) {
                    return value;
                }
            }
        } else {
            bitmapArrayReference = new SoftReference[numberOfBitmaps];
            bitmaps = new SoftReference<SoftReference<ImmutableRoaringBitmap>[]>(bitmapArrayReference);
        }
    } else {
        bitmapArrayReference = new SoftReference[numberOfBitmaps];
        bitmaps = new SoftReference<SoftReference<ImmutableRoaringBitmap>[]>(bitmapArrayReference);
    }
    synchronized (this) {
        ImmutableRoaringBitmap value;
        if (bitmapArrayReference[idx] == null || bitmapArrayReference[idx].get() == null) {
            value = buildRoaringBitmapForIndex(idx);
            bitmapArrayReference[idx] = new SoftReference<ImmutableRoaringBitmap>(value);
        } else {
            value = bitmapArrayReference[idx].get();
        }
        return value;
    }
}
Also used : SoftReference(java.lang.ref.SoftReference) ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap)

Example 15 with ImmutableRoaringBitmap

use of org.roaringbitmap.buffer.ImmutableRoaringBitmap in project pinot by linkedin.

the class BitmapDocIdSetTest method testSimple.

@Test
public void testSimple() throws IOException {
    int numBitMaps = 5;
    final int numDocs = 1000;
    List<ImmutableRoaringBitmap> list = new ArrayList<ImmutableRoaringBitmap>();
    Random r = new Random();
    TreeSet<Integer> originalSet = new TreeSet<Integer>();
    for (int i = 0; i < numBitMaps; i++) {
        MutableRoaringBitmap mutableRoaringBitmap = new MutableRoaringBitmap();
        int length = r.nextInt(numDocs);
        for (int j = 0; j < length; j++) {
            int docId = r.nextInt(numDocs);
            originalSet.add(docId);
            mutableRoaringBitmap.add(docId);
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(bos);
        // could call "rr1.runOptimize()" and "rr2.runOptimize" if there 
        // there were runs to compress
        mutableRoaringBitmap.serialize(dos);
        dos.close();
        ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray());
        ImmutableRoaringBitmap immutableRoaringBitmap = new ImmutableRoaringBitmap(bb);
        list.add(immutableRoaringBitmap);
    }
    ImmutableRoaringBitmap[] bitmaps = new ImmutableRoaringBitmap[list.size()];
    list.toArray(bitmaps);
    BlockMetadata blockMetadata = new BlockMetadata() {

        @Override
        public boolean isSparse() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean isSorted() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean isSingleValue() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean hasInvertedIndex() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean hasDictionary() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public int getStartDocId() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public int getSize() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public int getMaxNumberOfMultiValues() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public int getLength() {
            return numDocs;
        }

        @Override
        public int getEndDocId() {
            return numDocs - 1;
        }

        @Override
        public Dictionary getDictionary() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public DataType getDataType() {
            // TODO Auto-generated method stub
            return null;
        }
    };
    BitmapDocIdSet bitmapDocIdSet = new BitmapDocIdSet("testColumn", blockMetadata, 0, numDocs - 1, bitmaps);
    BlockDocIdIterator iterator = bitmapDocIdSet.iterator();
    int docId;
    TreeSet<Integer> result = new TreeSet<Integer>();
    while ((docId = iterator.next()) != Constants.EOF) {
        result.add(docId);
    }
    Assert.assertEquals(originalSet.size(), result.size());
    Assert.assertEquals(originalSet, result);
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BitmapDocIdSet(com.linkedin.pinot.core.operator.docidsets.BitmapDocIdSet) ByteBuffer(java.nio.ByteBuffer) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator) Random(java.util.Random) TreeSet(java.util.TreeSet) ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap) BlockMetadata(com.linkedin.pinot.core.common.BlockMetadata) Test(org.testng.annotations.Test)

Aggregations

ImmutableRoaringBitmap (org.roaringbitmap.buffer.ImmutableRoaringBitmap)18 ArrayList (java.util.ArrayList)5 MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)5 BlockDocIdIterator (com.linkedin.pinot.core.common.BlockDocIdIterator)4 BlockDocIdSet (com.linkedin.pinot.core.common.BlockDocIdSet)3 BitmapInvertedIndexReader (com.linkedin.pinot.core.segment.index.readers.BitmapInvertedIndexReader)3 PinotDataBuffer (com.linkedin.pinot.core.segment.memory.PinotDataBuffer)3 Test (org.junit.Test)3 IntPair (com.linkedin.pinot.common.utils.Pairs.IntPair)2 AndDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.AndDocIdIterator)2 BitmapDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator)2 RangelessBitmapDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.RangelessBitmapDocIdIterator)2 ColumnMetadata (com.linkedin.pinot.core.segment.index.ColumnMetadata)2 SegmentMetadataImpl (com.linkedin.pinot.core.segment.index.SegmentMetadataImpl)2 ColumnIndexContainer (com.linkedin.pinot.core.segment.index.column.ColumnIndexContainer)2 ImmutableDictionaryReader (com.linkedin.pinot.core.segment.index.readers.ImmutableDictionaryReader)2 InvertedIndexReader (com.linkedin.pinot.core.segment.index.readers.InvertedIndexReader)2 SegmentDirectory (com.linkedin.pinot.core.segment.store.SegmentDirectory)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2