Search in sources :

Example 11 with BlockDocIdSet

use of com.linkedin.pinot.core.common.BlockDocIdSet in project pinot by linkedin.

the class ChunkIndexCreationDriverImplTest method test6.

@Test(enabled = false)
public void test6() throws Exception {
    final IndexSegmentImpl segment = (IndexSegmentImpl) Loaders.IndexSegment.load(INDEX_DIR.listFiles()[0], ReadMode.mmap);
    final ImmutableDictionaryReader d = segment.getDictionaryFor("column7");
    final List<String> rhs = new ArrayList<String>();
    rhs.add(d.get(new Random().nextInt(d.length())).toString());
    final Predicate p = new EqPredicate("column7", rhs);
    final DataSource ds = segment.getDataSource("column7", p);
    final Block bl = ds.nextBlock();
    final BlockDocIdSet idSet = bl.getBlockDocIdSet();
    final BlockDocIdIterator it = idSet.iterator();
    int docId = it.next();
    final StringBuilder b = new StringBuilder();
    while (docId != Constants.EOF) {
        b.append(docId + ",");
        docId = it.next();
    }
//    System.out.println(b.toString());
}
Also used : ImmutableDictionaryReader(com.linkedin.pinot.core.segment.index.readers.ImmutableDictionaryReader) ArrayList(java.util.ArrayList) EqPredicate(com.linkedin.pinot.core.common.predicate.EqPredicate) EqPredicate(com.linkedin.pinot.core.common.predicate.EqPredicate) Predicate(com.linkedin.pinot.core.common.Predicate) DataSource(com.linkedin.pinot.core.common.DataSource) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator) IndexSegmentImpl(com.linkedin.pinot.core.segment.index.IndexSegmentImpl) Random(java.util.Random) BlockDocIdSet(com.linkedin.pinot.core.common.BlockDocIdSet) Block(com.linkedin.pinot.core.common.Block) Test(org.testng.annotations.Test)

Example 12 with BlockDocIdSet

use of com.linkedin.pinot.core.common.BlockDocIdSet in project pinot by linkedin.

the class AndOperatorTest method testIntersectionForTwoLists.

@Test
public void testIntersectionForTwoLists() {
    int[] list1 = new int[] { 2, 3, 10, 15, 16, 28 };
    int[] list2 = new int[] { 3, 6, 8, 20, 28 };
    List<BaseFilterOperator> operators = new ArrayList<>();
    operators.add(makeFilterOperator(list1));
    operators.add(makeFilterOperator(list2));
    final AndOperator andOperator = new AndOperator(operators);
    andOperator.open();
    BaseFilterBlock block;
    while ((block = andOperator.getNextBlock()) != null) {
        final BlockDocIdSet blockDocIdSet = block.getBlockDocIdSet();
        final BlockDocIdIterator iterator = blockDocIdSet.iterator();
        int docId;
        while ((docId = iterator.next()) != Constants.EOF) {
        //        System.out.println(docId);
        }
    }
    andOperator.close();
}
Also used : BaseFilterOperator(com.linkedin.pinot.core.operator.filter.BaseFilterOperator) AndOperator(com.linkedin.pinot.core.operator.filter.AndOperator) BlockDocIdSet(com.linkedin.pinot.core.common.BlockDocIdSet) ArrayList(java.util.ArrayList) BaseFilterBlock(com.linkedin.pinot.core.operator.blocks.BaseFilterBlock) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator) Test(org.testng.annotations.Test)

Example 13 with BlockDocIdSet

use of com.linkedin.pinot.core.common.BlockDocIdSet in project pinot by linkedin.

the class OrOperatorTest method testIntersectionForTwoLists.

@Test
public void testIntersectionForTwoLists() {
    int[] list1 = new int[] { 2, 3, 10, 15, 16, 28 };
    int[] list2 = new int[] { 3, 6, 8, 20, 28 };
    List<BaseFilterOperator> operators = new ArrayList<>();
    operators.add(makeFilterOperator(list1));
    operators.add(makeFilterOperator(list2));
    final OrOperator orOperator = new OrOperator(operators);
    orOperator.open();
    Block block;
    TreeSet<Integer> set = new TreeSet<Integer>();
    set.addAll(Lists.newArrayList(ArrayUtils.toObject(list1)));
    set.addAll(Lists.newArrayList(ArrayUtils.toObject(list2)));
    Iterator<Integer> expectedIterator = set.iterator();
    while ((block = orOperator.nextBlock()) != null) {
        final BlockDocIdSet blockDocIdSet = block.getBlockDocIdSet();
        final BlockDocIdIterator iterator = blockDocIdSet.iterator();
        int docId;
        while ((docId = iterator.next()) != Constants.EOF) {
            Assert.assertEquals(expectedIterator.next().intValue(), docId);
        }
    }
    orOperator.close();
}
Also used : OrOperator(com.linkedin.pinot.core.operator.filter.OrOperator) ArrayList(java.util.ArrayList) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator) BaseFilterOperator(com.linkedin.pinot.core.operator.filter.BaseFilterOperator) TreeSet(java.util.TreeSet) BlockDocIdSet(com.linkedin.pinot.core.common.BlockDocIdSet) Block(com.linkedin.pinot.core.common.Block) BaseFilterBlock(com.linkedin.pinot.core.operator.blocks.BaseFilterBlock) Test(org.testng.annotations.Test)

Example 14 with BlockDocIdSet

use of com.linkedin.pinot.core.common.BlockDocIdSet in project pinot by linkedin.

the class OrOperatorTest method testIntersectionForThreeLists.

@Test
public void testIntersectionForThreeLists() {
    int[] list1 = new int[] { 2, 3, 6, 10, 15, 16, 28 };
    int[] list2 = new int[] { 3, 6, 8, 20, 28 };
    int[] list3 = new int[] { 1, 2, 3, 6, 30 };
    List<BaseFilterOperator> operators = new ArrayList<>();
    operators.add(makeFilterOperator(list1));
    operators.add(makeFilterOperator(list2));
    operators.add(makeFilterOperator(list3));
    final OrOperator orOperator = new OrOperator(operators);
    orOperator.open();
    Block block;
    TreeSet<Integer> set = new TreeSet<Integer>();
    set.addAll(Lists.newArrayList(ArrayUtils.toObject(list1)));
    set.addAll(Lists.newArrayList(ArrayUtils.toObject(list2)));
    set.addAll(Lists.newArrayList(ArrayUtils.toObject(list3)));
    Iterator<Integer> expectedIterator = set.iterator();
    while ((block = orOperator.nextBlock()) != null) {
        final BlockDocIdSet blockDocIdSet = block.getBlockDocIdSet();
        final BlockDocIdIterator iterator = blockDocIdSet.iterator();
        int docId;
        while ((docId = iterator.next()) != Constants.EOF) {
            Assert.assertEquals(expectedIterator.next().intValue(), docId);
        }
    }
    orOperator.close();
}
Also used : OrOperator(com.linkedin.pinot.core.operator.filter.OrOperator) ArrayList(java.util.ArrayList) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator) BaseFilterOperator(com.linkedin.pinot.core.operator.filter.BaseFilterOperator) TreeSet(java.util.TreeSet) BlockDocIdSet(com.linkedin.pinot.core.common.BlockDocIdSet) Block(com.linkedin.pinot.core.common.Block) BaseFilterBlock(com.linkedin.pinot.core.operator.blocks.BaseFilterBlock) Test(org.testng.annotations.Test)

Example 15 with BlockDocIdSet

use of com.linkedin.pinot.core.common.BlockDocIdSet 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

BlockDocIdSet (com.linkedin.pinot.core.common.BlockDocIdSet)15 BlockDocIdIterator (com.linkedin.pinot.core.common.BlockDocIdIterator)14 ArrayList (java.util.ArrayList)13 Test (org.testng.annotations.Test)10 BaseFilterBlock (com.linkedin.pinot.core.operator.blocks.BaseFilterBlock)8 BaseFilterOperator (com.linkedin.pinot.core.operator.filter.BaseFilterOperator)8 Block (com.linkedin.pinot.core.common.Block)6 AndOperator (com.linkedin.pinot.core.operator.filter.AndOperator)4 OrOperator (com.linkedin.pinot.core.operator.filter.OrOperator)4 DataSource (com.linkedin.pinot.core.common.DataSource)3 Predicate (com.linkedin.pinot.core.common.Predicate)3 EqPredicate (com.linkedin.pinot.core.common.predicate.EqPredicate)3 IndexSegmentImpl (com.linkedin.pinot.core.segment.index.IndexSegmentImpl)3 TreeSet (java.util.TreeSet)3 ImmutableRoaringBitmap (org.roaringbitmap.buffer.ImmutableRoaringBitmap)3 MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)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