Search in sources :

Example 1 with BitmapDocIdIterator

use of com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator in project pinot by linkedin.

the class StarTreeIndexOperator method nextFilterBlock.

@Override
public BaseFilterBlock nextFilterBlock(BlockId blockId) {
    MutableRoaringBitmap finalResult = null;
    if (emptyResult) {
        finalResult = new MutableRoaringBitmap();
        final BitmapDocIdIterator bitmapDocIdIterator = new BitmapDocIdIterator(finalResult.getIntIterator());
        return createBaseFilterBlock(bitmapDocIdIterator);
    }
    List<BaseFilterOperator> matchingLeafOperators = buildMatchingLeafOperators();
    if (matchingLeafOperators.size() == 1) {
        BaseFilterOperator baseFilterOperator = (BaseFilterOperator) matchingLeafOperators.get(0);
        return baseFilterOperator.nextFilterBlock(blockId);
    } else {
        CompositeOperator compositeOperator = new CompositeOperator(matchingLeafOperators);
        return compositeOperator.nextFilterBlock(blockId);
    }
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) BitmapDocIdIterator(com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator)

Example 2 with BitmapDocIdIterator

use of com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator in project pinot by linkedin.

the class AndBlockDocIdSet method slowIterator.

public BlockDocIdIterator slowIterator() {
    List<BlockDocIdIterator> rawIterators = new ArrayList<>();
    boolean useBitmapBasedIntersection = false;
    for (BlockDocIdSet docIdSet : blockDocIdSets) {
        if (docIdSet instanceof BitmapDocIdSet) {
            useBitmapBasedIntersection = true;
        }
    }
    BlockDocIdIterator[] docIdIterators;
    if (useBitmapBasedIntersection) {
        List<ImmutableRoaringBitmap> allBitmaps = new ArrayList<ImmutableRoaringBitmap>();
        for (BlockDocIdSet docIdSet : blockDocIdSets) {
            if (docIdSet instanceof SortedDocIdSet) {
                MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
                SortedDocIdSet sortedDocIdSet = (SortedDocIdSet) docIdSet;
                List<IntPair> pairs = sortedDocIdSet.getRaw();
                for (IntPair pair : pairs) {
                    // add takes [start, end) i.e inclusive
                    bitmap.add(pair.getLeft(), pair.getRight() + 1);
                // start, exclusive end.
                }
                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);
            }
        }
        IntIterator intIterator;
        if (allBitmaps.size() > 1) {
            MutableRoaringBitmap answer = (MutableRoaringBitmap) allBitmaps.get(0).clone();
            for (int i = 1; i < allBitmaps.size(); i++) {
                answer.and(allBitmaps.get(i));
            }
            intIterator = answer.getIntIterator();
        } else {
            intIterator = allBitmaps.get(0).getIntIterator();
        }
        BitmapDocIdIterator singleBitmapBlockIdIterator = new BitmapDocIdIterator(intIterator);
        singleBitmapBlockIdIterator.setStartDocId(minDocId);
        singleBitmapBlockIdIterator.setEndDocId(maxDocId);
        rawIterators.add(0, singleBitmapBlockIdIterator);
        docIdIterators = new BlockDocIdIterator[rawIterators.size()];
        rawIterators.toArray(docIdIterators);
    } else {
        docIdIterators = new BlockDocIdIterator[blockDocIdSets.size()];
        for (int srcId = 0; srcId < blockDocIdSets.size(); srcId++) {
            docIdIterators[srcId] = blockDocIdSets.get(srcId).iterator();
        }
    }
    return new AndDocIdIterator(docIdIterators);
}
Also used : IntIterator(org.roaringbitmap.IntIterator) MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) ArrayList(java.util.ArrayList) IntPair(com.linkedin.pinot.common.utils.Pairs.IntPair) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator) BlockDocIdSet(com.linkedin.pinot.core.common.BlockDocIdSet) AndDocIdIterator(com.linkedin.pinot.core.operator.dociditerators.AndDocIdIterator) ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap) RangelessBitmapDocIdIterator(com.linkedin.pinot.core.operator.dociditerators.RangelessBitmapDocIdIterator) BitmapDocIdIterator(com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator)

Example 3 with BitmapDocIdIterator

use of com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator in project pinot by linkedin.

the class BitmapDocIdSet method iterator.

@Override
public BlockDocIdIterator iterator() {
    bitmapBasedBlockIdIterator = new BitmapDocIdIterator(answer.getIntIterator());
    bitmapBasedBlockIdIterator.setStartDocId(startDocId);
    bitmapBasedBlockIdIterator.setEndDocId(endDocId);
    return bitmapBasedBlockIdIterator;
}
Also used : BitmapDocIdIterator(com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator)

Example 4 with BitmapDocIdIterator

use of com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator 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

BitmapDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.BitmapDocIdIterator)4 MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)3 BlockDocIdIterator (com.linkedin.pinot.core.common.BlockDocIdIterator)2 BlockDocIdSet (com.linkedin.pinot.core.common.BlockDocIdSet)2 ArrayList (java.util.ArrayList)2 ImmutableRoaringBitmap (org.roaringbitmap.buffer.ImmutableRoaringBitmap)2 Pairs (com.linkedin.pinot.common.utils.Pairs)1 IntPair (com.linkedin.pinot.common.utils.Pairs.IntPair)1 AndDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.AndDocIdIterator)1 OrDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.OrDocIdIterator)1 RangelessBitmapDocIdIterator (com.linkedin.pinot.core.operator.dociditerators.RangelessBitmapDocIdIterator)1 IntIterator (org.roaringbitmap.IntIterator)1