Search in sources :

Example 31 with BlockDocIdIterator

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

Example 32 with BlockDocIdIterator

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

the class SortedDocIdSetTest method testEmpty.

@Test
public void testEmpty() {
    List<IntPair> pairs = new ArrayList<IntPair>();
    SortedDocIdSet sortedDocIdSet = new SortedDocIdSet("Datasource-testCol", pairs);
    BlockDocIdIterator iterator = sortedDocIdSet.iterator();
    List<Integer> result = new ArrayList<Integer>();
    int docId;
    while ((docId = iterator.next()) != Constants.EOF) {
        result.add(docId);
    }
    Assert.assertTrue(result.isEmpty(), "Expected empty result set but got:" + result);
}
Also used : ArrayList(java.util.ArrayList) SortedDocIdSet(com.linkedin.pinot.core.operator.docidsets.SortedDocIdSet) IntPair(com.linkedin.pinot.common.utils.Pairs.IntPair) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator) Test(org.testng.annotations.Test)

Example 33 with BlockDocIdIterator

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

the class SortedDocIdSetTest method testCustomRange.

private void testCustomRange(String rangeString) {
    String trim = rangeString.replace('[', ' ').replace(']', ' ').replace('(', ' ').replace(')', ' ').replaceAll("[\\s]+", "");
    String[] splits = trim.split(",");
    Assert.assertTrue(splits.length % 2 == 0);
    List<Integer> expectedList = new ArrayList<Integer>();
    List<IntPair> pairs = new ArrayList<IntPair>();
    for (int i = 0; i < splits.length; i += 2) {
        int start = Integer.parseInt(splits[i]);
        int end = Integer.parseInt(splits[i + 1]);
        for (int val = start; val <= end; val++) {
            expectedList.add(val);
        }
        pairs.add(Pairs.intPair(start, end));
    }
    SortedDocIdSet sortedDocIdSet = new SortedDocIdSet("Datasource-testCol", pairs);
    BlockDocIdIterator iterator = sortedDocIdSet.iterator();
    List<Integer> result = new ArrayList<Integer>();
    int docId;
    while ((docId = iterator.next()) != Constants.EOF) {
        result.add(docId);
    }
    Assert.assertEquals(result.size(), expectedList.size());
    Assert.assertEquals(result, expectedList);
}
Also used : ArrayList(java.util.ArrayList) SortedDocIdSet(com.linkedin.pinot.core.operator.docidsets.SortedDocIdSet) IntPair(com.linkedin.pinot.common.utils.Pairs.IntPair) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator)

Aggregations

BlockDocIdIterator (com.linkedin.pinot.core.common.BlockDocIdIterator)33 ArrayList (java.util.ArrayList)28 Test (org.testng.annotations.Test)24 BlockDocIdSet (com.linkedin.pinot.core.common.BlockDocIdSet)14 Block (com.linkedin.pinot.core.common.Block)13 DataSource (com.linkedin.pinot.core.common.DataSource)11 Predicate (com.linkedin.pinot.core.common.Predicate)11 EqPredicate (com.linkedin.pinot.core.common.predicate.EqPredicate)11 NEqPredicate (com.linkedin.pinot.core.common.predicate.NEqPredicate)8 RangePredicate (com.linkedin.pinot.core.common.predicate.RangePredicate)8 BaseFilterBlock (com.linkedin.pinot.core.operator.blocks.BaseFilterBlock)8 BaseFilterOperator (com.linkedin.pinot.core.operator.filter.BaseFilterOperator)8 RealtimeSegmentImplTest (com.linkedin.pinot.core.realtime.impl.kafka.RealtimeSegmentImplTest)8 IntPair (com.linkedin.pinot.common.utils.Pairs.IntPair)7 SortedDocIdSet (com.linkedin.pinot.core.operator.docidsets.SortedDocIdSet)5 MutableRoaringBitmap (org.roaringbitmap.buffer.MutableRoaringBitmap)5 BlockSingleValIterator (com.linkedin.pinot.core.common.BlockSingleValIterator)4 AndOperator (com.linkedin.pinot.core.operator.filter.AndOperator)4 BitmapBasedFilterOperator (com.linkedin.pinot.core.operator.filter.BitmapBasedFilterOperator)4 OrOperator (com.linkedin.pinot.core.operator.filter.OrOperator)4