Search in sources :

Example 16 with MutableRoaringBitmap

use of org.roaringbitmap.buffer.MutableRoaringBitmap in project druid by druid-io.

the class WrappedRoaringBitmap method and.

@Override
public void and(MutableBitmap mutableBitmap) {
    WrappedRoaringBitmap other = (WrappedRoaringBitmap) mutableBitmap;
    MutableRoaringBitmap unwrappedOtherBitmap = other.bitmap;
    bitmap.and(unwrappedOtherBitmap);
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap)

Example 17 with MutableRoaringBitmap

use of org.roaringbitmap.buffer.MutableRoaringBitmap in project druid by druid-io.

the class WrappedRoaringBitmap method andNot.

@Override
public void andNot(MutableBitmap mutableBitmap) {
    WrappedRoaringBitmap other = (WrappedRoaringBitmap) mutableBitmap;
    MutableRoaringBitmap unwrappedOtherBitmap = other.bitmap;
    bitmap.andNot(unwrappedOtherBitmap);
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap)

Example 18 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)

Example 19 with MutableRoaringBitmap

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

the class BitmapPerformanceBenchmark method and.

private static ImmutableRoaringBitmap and(List<ImmutableRoaringBitmap> bitMaps) {
    if (bitMaps.size() == 1) {
        return bitMaps.get(0);
    }
    MutableRoaringBitmap answer = ImmutableRoaringBitmap.and(bitMaps.get(0), bitMaps.get(1));
    long start = System.currentTimeMillis();
    for (int i = 2; i < bitMaps.size(); i++) {
        answer.and(bitMaps.get(i));
    }
    long end = System.currentTimeMillis();
    int[] cardinality = new int[bitMaps.size()];
    int[] sizes = new int[bitMaps.size()];
    for (int i = 0; i < bitMaps.size(); i++) {
        ImmutableRoaringBitmap immutableRoaringBitmap = bitMaps.get(i);
        cardinality[i] = immutableRoaringBitmap.getCardinality();
        sizes[i] = immutableRoaringBitmap.getSizeInBytes();
    }
    bitMaps.get(0).getCardinality();
    System.out.println("AND operation Took " + (end - start));
    System.out.println("\toutput cardinality:" + answer.getCardinality());
    System.out.println("\toutout sizes:" + answer.getSizeInBytes());
    return answer;
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap)

Example 20 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)

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