Search in sources :

Example 11 with MutableBitmap

use of io.druid.collections.bitmap.MutableBitmap in project druid by druid-io.

the class StringDimensionMergerV9 method mergeBitmaps.

static void mergeBitmaps(List<IntBuffer> segmentRowNumConversions, Indexed<String> dimVals, BitmapFactory bmpFactory, RTree tree, boolean hasSpatial, IndexSeeker[] dictIdSeeker, int dictId, List<IndexableAdapter> adapters, String dimensionName, MutableBitmap nullRowsBitmap, GenericIndexedWriter<ImmutableBitmap> bitmapWriter) throws IOException {
    List<ConvertingIndexedInts> convertedInvertedIndexesToMerge = Lists.newArrayListWithCapacity(adapters.size());
    for (int j = 0; j < adapters.size(); ++j) {
        int seekedDictId = dictIdSeeker[j].seek(dictId);
        if (seekedDictId != IndexSeeker.NOT_EXIST) {
            convertedInvertedIndexesToMerge.add(new ConvertingIndexedInts(adapters.get(j).getBitmapIndex(dimensionName, seekedDictId), segmentRowNumConversions.get(j)));
        }
    }
    MutableBitmap mergedIndexes = bmpFactory.makeEmptyMutableBitmap();
    List<IntIterator> convertedInvertedIndexesIterators = new ArrayList<>(convertedInvertedIndexesToMerge.size());
    for (ConvertingIndexedInts convertedInvertedIndexes : convertedInvertedIndexesToMerge) {
        convertedInvertedIndexesIterators.add(convertedInvertedIndexes.iterator());
    }
    // Merge ascending index iterators into a single one, remove duplicates, and add to the mergedIndexes bitmap.
    // Merge is needed, because some compacting MutableBitmap implementations are very inefficient when bits are
    // added not in the ascending order.
    int prevRow = IndexMerger.INVALID_ROW;
    for (IntIterator mergeIt = IntIteratorUtils.mergeAscending(convertedInvertedIndexesIterators); mergeIt.hasNext(); ) {
        int row = mergeIt.nextInt();
        if (row != prevRow && row != IndexMerger.INVALID_ROW) {
            mergedIndexes.add(row);
        }
        prevRow = row;
    }
    if ((dictId == 0) && (Iterables.getFirst(dimVals, "") == null)) {
        mergedIndexes.or(nullRowsBitmap);
    }
    bitmapWriter.write(bmpFactory.makeImmutableBitmap(mergedIndexes));
    if (hasSpatial) {
        String dimVal = dimVals.get(dictId);
        if (dimVal != null) {
            List<String> stringCoords = Lists.newArrayList(SPLITTER.split(dimVal));
            float[] coords = new float[stringCoords.size()];
            for (int j = 0; j < coords.length; j++) {
                coords[j] = Float.valueOf(stringCoords.get(j));
            }
            tree.insert(coords, mergedIndexes);
        }
    }
}
Also used : AbstractIntIterator(it.unimi.dsi.fastutil.ints.AbstractIntIterator) IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) MutableBitmap(io.druid.collections.bitmap.MutableBitmap) ArrayList(java.util.ArrayList)

Example 12 with MutableBitmap

use of io.druid.collections.bitmap.MutableBitmap in project druid by druid-io.

the class TestIntegerSet method testSimpleAdd.

@Test
public void testSimpleAdd() throws IllegalAccessException, InstantiationException {
    for (Class<? extends MutableBitmap> clazz : clazzes) {
        MutableBitmap wrappedBitmap = clazz.newInstance();
        IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits());
        IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap);
        Set<Integer> set = IntSetTestUtility.getSetBits();
        set.add(999);
        integerSet.add(999);
        Assert.assertTrue(Sets.difference(integerSet, set).isEmpty());
        integerSet.add(58577);
        Assert.assertFalse(Sets.difference(integerSet, set).isEmpty());
    }
}
Also used : MutableBitmap(io.druid.collections.bitmap.MutableBitmap) Test(org.junit.Test)

Example 13 with MutableBitmap

use of io.druid.collections.bitmap.MutableBitmap in project druid by druid-io.

the class TestIntegerSet method testContainsAll.

@Test
public void testContainsAll() throws IllegalAccessException, InstantiationException {
    for (Class<? extends MutableBitmap> clazz : clazzes) {
        MutableBitmap wrappedBitmap = clazz.newInstance();
        IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits());
        IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap);
        Set<Integer> set = IntSetTestUtility.getSetBits();
        Assert.assertTrue(integerSet.containsAll(set));
        set.add(999);
        Assert.assertFalse(integerSet.containsAll(set));
    }
}
Also used : MutableBitmap(io.druid.collections.bitmap.MutableBitmap) Test(org.junit.Test)

Example 14 with MutableBitmap

use of io.druid.collections.bitmap.MutableBitmap in project druid by druid-io.

the class TestIntegerSet method testToSmallArray.

@Test
public void testToSmallArray() throws IllegalAccessException, InstantiationException {
    for (Class<? extends MutableBitmap> clazz : clazzes) {
        Exception e = null;
        MutableBitmap wrappedBitmap = clazz.newInstance();
        IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits());
        IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap);
        Set<Integer> set = Sets.newHashSet((Integer[]) integerSet.toArray(new Integer[0]));
        Assert.assertTrue(Sets.difference(integerSet, set).isEmpty());
    }
}
Also used : MutableBitmap(io.druid.collections.bitmap.MutableBitmap) Test(org.junit.Test)

Example 15 with MutableBitmap

use of io.druid.collections.bitmap.MutableBitmap in project druid by druid-io.

the class TestIntegerSet method testToBigArray.

@Test
public void testToBigArray() throws IllegalAccessException, InstantiationException {
    for (Class<? extends MutableBitmap> clazz : clazzes) {
        Exception e = null;
        MutableBitmap wrappedBitmap = clazz.newInstance();
        IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits());
        IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap);
        Integer[] bigArray = new Integer[1024];
        integerSet.toArray(bigArray);
        Set<Integer> set = Sets.newHashSet(bigArray);
        Assert.assertTrue(Sets.difference(integerSet, set).isEmpty());
    }
}
Also used : MutableBitmap(io.druid.collections.bitmap.MutableBitmap) Test(org.junit.Test)

Aggregations

MutableBitmap (io.druid.collections.bitmap.MutableBitmap)28 Test (org.junit.Test)15 ImmutableBitmap (io.druid.collections.bitmap.ImmutableBitmap)7 BitmapFactory (io.druid.collections.bitmap.BitmapFactory)5 BitmapIndexSelector (io.druid.query.filter.BitmapIndexSelector)4 BitmapIndex (io.druid.segment.column.BitmapIndex)4 BenchmarkOptions (com.carrotsearch.junitbenchmarks.BenchmarkOptions)3 Function (com.google.common.base.Function)3 RoaringBitmapFactory (io.druid.collections.bitmap.RoaringBitmapFactory)3 ImmutableRTree (io.druid.collections.spatial.ImmutableRTree)3 BitmapSerdeFactory (io.druid.segment.data.BitmapSerdeFactory)3 GenericIndexed (io.druid.segment.data.GenericIndexed)3 Indexed (io.druid.segment.data.Indexed)3 RoaringBitmapSerdeFactory (io.druid.segment.data.RoaringBitmapSerdeFactory)3 BitmapIndexColumnPartSupplier (io.druid.segment.serde.BitmapIndexColumnPartSupplier)3 Setup (org.openjdk.jmh.annotations.Setup)3 ConciseBitmapFactory (io.druid.collections.bitmap.ConciseBitmapFactory)1 WrappedImmutableRoaringBitmap (io.druid.collections.bitmap.WrappedImmutableRoaringBitmap)1 WrappedRoaringBitmap (io.druid.collections.bitmap.WrappedRoaringBitmap)1 EmptyIntIterator (io.druid.extendedset.intset.EmptyIntIterator)1