Search in sources :

Example 21 with MutableRoaringBitmap

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

the class SVScanDocIdIterator method applyAnd.

@Override
public MutableRoaringBitmap applyAnd(MutableRoaringBitmap answer) {
    MutableRoaringBitmap result = new MutableRoaringBitmap();
    if (evaluator.alwaysFalse()) {
        return result;
    }
    IntIterator intIterator = answer.getIntIterator();
    int docId = -1;
    while (intIterator.hasNext() && docId < endDocId) {
        docId = intIterator.next();
        if (docId >= startDocId) {
            valueIterator.skipTo(docId);
            _numEntriesScanned++;
            if (evaluator.apply(valueIterator.nextIntVal())) {
                result.add(docId);
            }
        }
    }
    return result;
}
Also used : IntIterator(org.roaringbitmap.IntIterator) MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap)

Example 22 with MutableRoaringBitmap

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

the class OrBlockDocIdSet method iterator.

@Override
public BlockDocIdIterator iterator() {
    List<BlockDocIdIterator> rawIterators = new ArrayList<>();
    boolean useBitmapOr = false;
    for (BlockDocIdSet docIdSet : docIdSets) {
        if (docIdSet instanceof BitmapDocIdSet) {
            useBitmapOr = true;
        }
    }
    if (useBitmapOr) {
        List<ImmutableRoaringBitmap> allBitmaps = new ArrayList<ImmutableRoaringBitmap>();
        for (BlockDocIdSet docIdSet : docIdSets) {
            if (docIdSet instanceof SortedDocIdSet) {
                MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
                SortedDocIdSet sortedDocIdSet = (SortedDocIdSet) docIdSet;
                List<Pairs.IntPair> pairs = sortedDocIdSet.getRaw();
                for (Pairs.IntPair pair : pairs) {
                    //add takes [start, end) i.e inclusive start, exclusive end.
                    bitmap.add(pair.getLeft(), pair.getRight() + 1);
                }
                allBitmaps.add(bitmap);
            } else if (docIdSet instanceof BitmapDocIdSet) {
                BitmapDocIdSet bitmapDocIdSet = (BitmapDocIdSet) docIdSet;
                ImmutableRoaringBitmap childBitmap = bitmapDocIdSet.getRaw();
                allBitmaps.add(childBitmap);
            } else {
                BlockDocIdIterator iterator = docIdSet.iterator();
                rawIterators.add(iterator);
            }
        }
        MutableRoaringBitmap answer = allBitmaps.get(0).toMutableRoaringBitmap();
        for (int i = 1; i < allBitmaps.size(); i++) {
            answer.or(allBitmaps.get(i));
        }
        intIterator = answer.getIntIterator();
        BitmapDocIdIterator singleBitmapBlockIdIterator = new BitmapDocIdIterator(intIterator);
        singleBitmapBlockIdIterator.setStartDocId(minDocId);
        singleBitmapBlockIdIterator.setEndDocId(maxDocId);
        rawIterators.add(singleBitmapBlockIdIterator);
        docIdIterators = new BlockDocIdIterator[rawIterators.size()];
        rawIterators.toArray(docIdIterators);
    } else {
        docIdIterators = new BlockDocIdIterator[docIdSets.size()];
        for (int srcId = 0; srcId < docIdSets.size(); srcId++) {
            docIdIterators[srcId] = docIdSets.get(srcId).iterator();
        }
    }
    //    if (docIdIterators.length == 1) {
    //      return docIdIterators[0];
    //    } else {
    OrDocIdIterator orDocIdIterator = new OrDocIdIterator(docIdIterators);
    orDocIdIterator.setStartDocId(minDocId);
    orDocIdIterator.setEndDocId(maxDocId);
    return orDocIdIterator;
//    }
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) ArrayList(java.util.ArrayList) Pairs(com.linkedin.pinot.common.utils.Pairs) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator) BlockDocIdSet(com.linkedin.pinot.core.common.BlockDocIdSet) ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap) BitmapDocIdIterator(com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator) OrDocIdIterator(com.linkedin.pinot.core.operator.dociditerators.OrDocIdIterator)

Example 23 with MutableRoaringBitmap

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

the class HeapBitmapInvertedIndexCreator method seal.

@Override
public void seal() throws IOException {
    final DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(invertedIndexFile)));
    // First, write out offsets of bitmaps. The information can be used to access a certain bitmap directly.
    // Totally (invertedIndex.length+1) offsets will be written out; the last offset is used to calculate the length of
    // the last bitmap, which might be needed when accessing bitmaps randomly.
    // If a bitmap's offset is k, then k bytes need to be skipped to reach the bitmap.
    // The first bitmap's offset
    int offset = 4 * (invertedIndex.length + 1);
    out.writeInt(offset);
    for (final MutableRoaringBitmap element : invertedIndex) {
        // the other bitmap's offset
        offset += element.serializedSizeInBytes();
        out.writeInt(offset);
    }
    // write out bitmaps one by one
    for (final MutableRoaringBitmap element : invertedIndex) {
        element.serialize(out);
    }
    out.close();
    LOGGER.debug("persisted bitmap inverted index for column : " + spec.getName() + " in " + invertedIndexFile.getAbsolutePath());
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 24 with MutableRoaringBitmap

use of org.roaringbitmap.buffer.MutableRoaringBitmap 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

MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)24 BlockDocIdIterator (com.linkedin.pinot.core.common.BlockDocIdIterator)5 ArrayList (java.util.ArrayList)5 ImmutableRoaringBitmap (org.roaringbitmap.buffer.ImmutableRoaringBitmap)5 DataOutputStream (java.io.DataOutputStream)4 BlockDocIdSet (com.linkedin.pinot.core.common.BlockDocIdSet)3 BitmapDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator)3 IntIterator (org.roaringbitmap.IntIterator)3 IntPair (com.linkedin.pinot.common.utils.Pairs.IntPair)2 AndDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.AndDocIdIterator)2 RangelessBitmapDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.RangelessBitmapDocIdIterator)2 ConciseSet (io.druid.extendedset.intset.ConciseSet)2 ImmutableConciseSet (io.druid.extendedset.intset.ImmutableConciseSet)2 BufferedOutputStream (java.io.BufferedOutputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 BitSet (java.util.BitSet)2 BeforeClass (org.junit.BeforeClass)2 Test (org.testng.annotations.Test)2