Search in sources :

Example 1 with Pairs

use of com.linkedin.pinot.common.utils.Pairs 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)

Aggregations

Pairs (com.linkedin.pinot.common.utils.Pairs)1 BlockDocIdIterator (com.linkedin.pinot.core.common.BlockDocIdIterator)1 BlockDocIdSet (com.linkedin.pinot.core.common.BlockDocIdSet)1 BitmapDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator)1 OrDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.OrDocIdIterator)1 ArrayList (java.util.ArrayList)1 ImmutableRoaringBitmap (org.roaringbitmap.buffer.ImmutableRoaringBitmap)1 MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)1