Search in sources :

Example 26 with MutableBitmap

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

the class TestIntegerSet method testRetainAll.

@Test
public void testRetainAll() 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.remove(1);
        set.add(9999);
        boolean threwError = false;
        try {
            integerSet.retainAll(set);
        } catch (UnsupportedOperationException ex) {
            threwError = true;
        }
        Assert.assertTrue(threwError);
    }
}
Also used : MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) Test(org.junit.Test)

Example 27 with MutableBitmap

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

Example 28 with MutableBitmap

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

the class TestIntegerSet method testIsEmpty.

@Test
public void testIsEmpty() throws IllegalAccessException, InstantiationException {
    for (Class<? extends MutableBitmap> clazz : clazzes) {
        MutableBitmap wrappedBitmap = clazz.newInstance();
        IntSetTestUtility.addAllToMutable(wrappedBitmap, IntSetTestUtility.getSetBits());
        IntegerSet integerSet = IntegerSet.wrap(wrappedBitmap);
        Assert.assertFalse(integerSet.isEmpty());
        integerSet.clear();
        Assert.assertTrue(integerSet.isEmpty());
        integerSet.add(1);
        Assert.assertFalse(integerSet.isEmpty());
    }
}
Also used : MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) Test(org.junit.Test)

Example 29 with MutableBitmap

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

the class DictionaryEncodedColumnMerger method writeIndexes.

@Override
public void writeIndexes(@Nullable List<IntBuffer> segmentRowNumConversions) throws IOException {
    if (!capabilities.hasBitmapIndexes()) {
        return;
    }
    long dimStartTime = System.currentTimeMillis();
    final BitmapSerdeFactory bitmapSerdeFactory = indexSpec.getBitmapSerdeFactory();
    String bmpFilename = StringUtils.format("%s.inverted", dimensionName);
    bitmapWriter = new GenericIndexedWriter<>(segmentWriteOutMedium, bmpFilename, indexSpec.getBitmapSerdeFactory().getObjectStrategy());
    bitmapWriter.open();
    bitmapWriter.setObjectsNotSorted();
    BitmapFactory bitmapFactory = bitmapSerdeFactory.getBitmapFactory();
    ExtendedIndexesMerger extendedIndexesMerger = getExtendedIndexesMerger();
    if (extendedIndexesMerger != null) {
        extendedIndexesMerger.initialize();
    }
    IndexSeeker[] dictIdSeeker = toIndexSeekers(adapters, dimConversions, dimensionName);
    // Iterate all dim values's dictionary id in ascending order which in line with dim values's compare result.
    for (int dictId = 0; dictId < dictionarySize; dictId++) {
        progress.progress();
        MutableBitmap mergedIndexes = mergeBitmaps(segmentRowNumConversions, bitmapFactory, dictIdSeeker, dictId);
        if (extendedIndexesMerger != null) {
            extendedIndexesMerger.mergeIndexes(dictId, mergedIndexes);
        }
    }
    if (extendedIndexesMerger != null) {
        extendedIndexesMerger.write();
    }
    log.debug("Completed dim[%s] inverted with cardinality[%,d] in %,d millis.", dimensionName, dictionarySize, System.currentTimeMillis() - dimStartTime);
    if (dictionaryMergeIterator != null) {
        dictionaryMergeIterator.close();
    }
}
Also used : MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) BitmapFactory(org.apache.druid.collections.bitmap.BitmapFactory) BitmapSerdeFactory(org.apache.druid.segment.data.BitmapSerdeFactory)

Example 30 with MutableBitmap

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

the class IncrementalIndexAdapter method processRows.

/**
 * Sometimes it's hard to tell whether one dimension contains a null value or not.
 * If one dimension had show a null or empty value explicitly, then yes, it contains
 * null value. But if one dimension's values are all non-null, it still early to say
 * this dimension does not contain null value. Consider a two row case, first row had
 * "dimA=1" and "dimB=2", the second row only had "dimA=3". To dimB, its value are "2" and
 * never showed a null or empty value. But when we combines these two rows, dimB is null
 * in row 2. So we should iterate all rows to determine whether one dimension contains
 * a null value.
 */
private void processRows(IncrementalIndex index, BitmapFactory bitmapFactory, List<IncrementalIndex.DimensionDesc> dimensions) {
    int rowNum = 0;
    for (IncrementalIndexRow row : index.getFacts().persistIterable()) {
        final Object[] dims = row.getDims();
        for (IncrementalIndex.DimensionDesc dimension : dimensions) {
            final int dimIndex = dimension.getIndex();
            DimensionAccessor accessor = accessors.get(dimension.getName());
            // Add 'null' to the dimension's dictionary.
            if (dimIndex >= dims.length || dims[dimIndex] == null) {
                accessor.indexer.processRowValsToUnsortedEncodedKeyComponent(null, true);
                continue;
            }
            final ColumnCapabilities capabilities = dimension.getCapabilities();
            if (capabilities.hasBitmapIndexes()) {
                final MutableBitmap[] bitmapIndexes = accessor.invertedIndexes;
                final DimensionIndexer indexer = accessor.indexer;
                indexer.fillBitmapsFromUnsortedEncodedKeyComponent(dims[dimIndex], rowNum, bitmapIndexes, bitmapFactory);
            }
        }
        ++rowNum;
    }
}
Also used : DimensionIndexer(org.apache.druid.segment.DimensionIndexer) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities)

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