Search in sources :

Example 6 with MutableBitmap

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

the class TestIntegerSet method testIntOverflow.

@Test
public void testIntOverflow() throws IllegalAccessException, InstantiationException {
    for (Class<? extends MutableBitmap> clazz : clazzes) {
        Exception e = null;
        try {
            MutableBitmap wrappedBitmap = clazz.newInstance();
            IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits());
            IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap);
            integerSet.add(Integer.MAX_VALUE + 1);
        } catch (IllegalArgumentException ex) {
            e = ex;
        }
        Assert.assertNotNull(e);
    }
}
Also used : MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) Test(org.junit.Test)

Example 7 with MutableBitmap

use of org.apache.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) {
        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(org.apache.druid.collections.bitmap.MutableBitmap) Test(org.junit.Test)

Example 8 with MutableBitmap

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

the class FiltersTest method makeNonOverlappedBitmapIndexes.

private static BitmapIndex makeNonOverlappedBitmapIndexes(final int bitmapNum, final List<ImmutableBitmap> bitmaps) {
    final BitmapIndex bitmapIndex = getBitmapIndex(bitmaps);
    final BitmapFactory factory = bitmapIndex.getBitmapFactory();
    for (int i = 0; i < bitmapNum; i++) {
        final MutableBitmap mutableBitmap = factory.makeEmptyMutableBitmap();
        for (int j = 0; j < 10; j++) {
            mutableBitmap.add(i * 10 + j);
        }
        bitmaps.add(factory.makeImmutableBitmap(mutableBitmap));
    }
    return bitmapIndex;
}
Also used : MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) BitmapIndex(org.apache.druid.segment.column.BitmapIndex) BitmapFactory(org.apache.druid.collections.bitmap.BitmapFactory) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory)

Example 9 with MutableBitmap

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

the class BitmapOffsetTest method testSanity.

@Test
public void testSanity() {
    MutableBitmap mutable = factory.makeEmptyMutableBitmap();
    for (int val : TEST_VALS) {
        mutable.add(val);
    }
    ImmutableBitmap bitmap = factory.makeImmutableBitmap(mutable);
    final BitmapOffset offset = BitmapOffset.of(bitmap, descending, bitmap.size());
    final int[] expected = descending ? TEST_VALS_FLIP : TEST_VALS;
    int count = 0;
    while (offset.withinBounds()) {
        Assert.assertEquals(expected[count], offset.getOffset());
        int cloneCount = count;
        Offset clonedOffset = offset.clone();
        while (clonedOffset.withinBounds()) {
            Assert.assertEquals(expected[cloneCount], clonedOffset.getOffset());
            ++cloneCount;
            clonedOffset.increment();
        }
        ++count;
        offset.increment();
    }
    Assert.assertEquals(count, expected.length);
}
Also used : ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) Offset(org.apache.druid.segment.data.Offset) Test(org.junit.Test)

Example 10 with MutableBitmap

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

the class DictionaryEncodedColumnMerger method mergeBitmaps.

protected MutableBitmap mergeBitmaps(@Nullable List<IntBuffer> segmentRowNumConversions, BitmapFactory bmpFactory, IndexSeeker[] dictIdSeeker, int dictId) throws IOException {
    List<IntIterable> convertedInvertedIndexesToMerge = Lists.newArrayListWithCapacity(adapters.size());
    for (int j = 0; j < adapters.size(); ++j) {
        int seekedDictId = dictIdSeeker[j].seek(dictId);
        if (seekedDictId != IndexSeeker.NOT_EXIST) {
            IntIterable values;
            if (segmentRowNumConversions != null) {
                values = new ConvertingBitmapValues(adapters.get(j).getBitmapValues(dimensionName, seekedDictId), segmentRowNumConversions.get(j));
            } else {
                BitmapValues bitmapValues = adapters.get(j).getBitmapValues(dimensionName, seekedDictId);
                values = bitmapValues::iterator;
            }
            convertedInvertedIndexesToMerge.add(values);
        }
    }
    MutableBitmap mergedIndexes = bmpFactory.makeEmptyMutableBitmap();
    List<IntIterator> convertedInvertedIndexesIterators = new ArrayList<>(convertedInvertedIndexesToMerge.size());
    for (IntIterable 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 && firstDictionaryValue == null) {
        mergedIndexes.or(nullRowsBitmap);
    }
    bitmapWriter.write(bmpFactory.makeImmutableBitmap(mergedIndexes));
    return mergedIndexes;
}
Also used : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) ArrayList(java.util.ArrayList) BitmapValues(org.apache.druid.segment.data.BitmapValues) IntIterable(it.unimi.dsi.fastutil.ints.IntIterable)

Aggregations

MutableBitmap (org.apache.druid.collections.bitmap.MutableBitmap)33 Test (org.junit.Test)15 BitmapFactory (org.apache.druid.collections.bitmap.BitmapFactory)8 ImmutableBitmap (org.apache.druid.collections.bitmap.ImmutableBitmap)7 RoaringBitmapFactory (org.apache.druid.collections.bitmap.RoaringBitmapFactory)6 Setup (org.openjdk.jmh.annotations.Setup)6 ArrayList (java.util.ArrayList)4 ConciseBitmapFactory (org.apache.druid.collections.bitmap.ConciseBitmapFactory)4 BitmapIndex (org.apache.druid.segment.column.BitmapIndex)4 BitmapSerdeFactory (org.apache.druid.segment.data.BitmapSerdeFactory)4 Benchmark (org.openjdk.jmh.annotations.Benchmark)4 BenchmarkOptions (com.carrotsearch.junitbenchmarks.BenchmarkOptions)3 Function (com.google.common.base.Function)3 List (java.util.List)3 Random (java.util.Random)3 TimeUnit (java.util.concurrent.TimeUnit)3 NullHandling (org.apache.druid.common.config.NullHandling)3 IAE (org.apache.druid.java.util.common.IAE)3 RoaringBitmapSerdeFactory (org.apache.druid.segment.data.RoaringBitmapSerdeFactory)3 StringBitmapIndexColumnPartSupplier (org.apache.druid.segment.serde.StringBitmapIndexColumnPartSupplier)3