Search in sources :

Example 6 with BitmapSerdeFactory

use of org.apache.druid.segment.data.BitmapSerdeFactory 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 7 with BitmapSerdeFactory

use of org.apache.druid.segment.data.BitmapSerdeFactory in project druid by druid-io.

the class StringDimensionMergerV9 method makeColumnDescriptor.

@Override
public ColumnDescriptor makeColumnDescriptor() {
    // Now write everything
    boolean hasMultiValue = capabilities.hasMultipleValues().isTrue();
    final CompressionStrategy compressionStrategy = indexSpec.getDimensionCompression();
    final BitmapSerdeFactory bitmapSerdeFactory = indexSpec.getBitmapSerdeFactory();
    final ColumnDescriptor.Builder builder = ColumnDescriptor.builder();
    builder.setValueType(ValueType.STRING);
    builder.setHasMultipleValues(hasMultiValue);
    final DictionaryEncodedColumnPartSerde.SerializerBuilder partBuilder = DictionaryEncodedColumnPartSerde.serializerBuilder().withDictionary(dictionaryWriter).withValue(encodedValueSerializer, hasMultiValue, compressionStrategy != CompressionStrategy.UNCOMPRESSED).withBitmapSerdeFactory(bitmapSerdeFactory).withBitmapIndex(bitmapWriter).withSpatialIndex(spatialWriter).withByteOrder(IndexIO.BYTE_ORDER);
    return builder.addSerde(partBuilder.build()).build();
}
Also used : ColumnDescriptor(org.apache.druid.segment.column.ColumnDescriptor) CompressionStrategy(org.apache.druid.segment.data.CompressionStrategy) DictionaryEncodedColumnPartSerde(org.apache.druid.segment.serde.DictionaryEncodedColumnPartSerde) BitmapSerdeFactory(org.apache.druid.segment.data.BitmapSerdeFactory)

Example 8 with BitmapSerdeFactory

use of org.apache.druid.segment.data.BitmapSerdeFactory in project druid by druid-io.

the class BaseFilterTest method makeConstructors.

public static Collection<Object[]> makeConstructors() {
    final List<Object[]> constructors = new ArrayList<>();
    final Map<String, BitmapSerdeFactory> bitmapSerdeFactories = ImmutableMap.of("concise", new ConciseBitmapSerdeFactory(), "roaring", new RoaringBitmapSerdeFactory(true));
    final Map<String, SegmentWriteOutMediumFactory> segmentWriteOutMediumFactories = ImmutableMap.of("tmpFile segment write-out medium", TmpFileSegmentWriteOutMediumFactory.instance(), "off-heap memory segment write-out medium", OffHeapMemorySegmentWriteOutMediumFactory.instance());
    final Map<String, Function<IndexBuilder, Pair<StorageAdapter, Closeable>>> finishers = ImmutableMap.<String, Function<IndexBuilder, Pair<StorageAdapter, Closeable>>>builder().put("incremental", input -> {
        final IncrementalIndex index = input.buildIncrementalIndex();
        return Pair.of(new IncrementalIndexStorageAdapter(index), index);
    }).put("mmapped", input -> {
        final QueryableIndex index = input.buildMMappedIndex();
        return Pair.of(new QueryableIndexStorageAdapter(index), index);
    }).put("mmappedMerged", input -> {
        final QueryableIndex index = input.buildMMappedMergedIndex();
        return Pair.of(new QueryableIndexStorageAdapter(index), index);
    }).put("rowBasedWithoutTypeSignature", input -> Pair.of(input.buildRowBasedSegmentWithoutTypeSignature().asStorageAdapter(), () -> {
    })).put("rowBasedWithTypeSignature", input -> Pair.of(input.buildRowBasedSegmentWithTypeSignature().asStorageAdapter(), () -> {
    })).build();
    for (Map.Entry<String, BitmapSerdeFactory> bitmapSerdeFactoryEntry : bitmapSerdeFactories.entrySet()) {
        for (Map.Entry<String, SegmentWriteOutMediumFactory> segmentWriteOutMediumFactoryEntry : segmentWriteOutMediumFactories.entrySet()) {
            for (Map.Entry<String, Function<IndexBuilder, Pair<StorageAdapter, Closeable>>> finisherEntry : finishers.entrySet()) {
                for (boolean cnf : ImmutableList.of(false, true)) {
                    for (boolean optimize : ImmutableList.of(false, true)) {
                        final String testName = StringUtils.format("bitmaps[%s], indexMerger[%s], finisher[%s], cnf[%s], optimize[%s]", bitmapSerdeFactoryEntry.getKey(), segmentWriteOutMediumFactoryEntry.getKey(), finisherEntry.getKey(), cnf, optimize);
                        final IndexBuilder indexBuilder = IndexBuilder.create().schema(DEFAULT_INDEX_SCHEMA).indexSpec(new IndexSpec(bitmapSerdeFactoryEntry.getValue(), null, null, null)).segmentWriteOutMediumFactory(segmentWriteOutMediumFactoryEntry.getValue());
                        constructors.add(new Object[] { testName, indexBuilder, finisherEntry.getValue(), cnf, optimize });
                    }
                }
            }
        }
    }
    return constructors;
}
Also used : Arrays(java.util.Arrays) LongDimensionSchema(org.apache.druid.data.input.impl.LongDimensionSchema) RowAdapters(org.apache.druid.segment.RowAdapters) IndexSpec(org.apache.druid.segment.IndexSpec) ExprType(org.apache.druid.math.expr.ExprType) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) IndexedInts(org.apache.druid.segment.data.IndexedInts) StorageAdapter(org.apache.druid.segment.StorageAdapter) TmpFileSegmentWriteOutMediumFactory(org.apache.druid.segment.writeout.TmpFileSegmentWriteOutMediumFactory) ByteBuffer(java.nio.ByteBuffer) Pair(org.apache.druid.java.util.common.Pair) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) IncrementalIndexStorageAdapter(org.apache.druid.segment.incremental.IncrementalIndexStorageAdapter) ExpressionType(org.apache.druid.math.expr.ExpressionType) Expr(org.apache.druid.math.expr.Expr) Map(java.util.Map) ConciseBitmapSerdeFactory(org.apache.druid.segment.data.ConciseBitmapSerdeFactory) OffHeapMemorySegmentWriteOutMediumFactory(org.apache.druid.segment.writeout.OffHeapMemorySegmentWriteOutMediumFactory) Parameterized(org.junit.runners.Parameterized) DateTimes(org.apache.druid.java.util.common.DateTimes) Sequence(org.apache.druid.java.util.common.guava.Sequence) RowBasedColumnSelectorFactory(org.apache.druid.segment.RowBasedColumnSelectorFactory) RoaringBitmapSerdeFactory(org.apache.druid.segment.data.RoaringBitmapSerdeFactory) Function(com.google.common.base.Function) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) QueryableIndex(org.apache.druid.segment.QueryableIndex) StringUtils(org.apache.druid.java.util.common.StringUtils) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) IndexBuilder(org.apache.druid.segment.IndexBuilder) VectorObjectSelector(org.apache.druid.segment.vector.VectorObjectSelector) InputRowParser(org.apache.druid.data.input.impl.InputRowParser) TestExprMacroTable(org.apache.druid.query.expression.TestExprMacroTable) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) IncrementalIndexSchema(org.apache.druid.segment.incremental.IncrementalIndexSchema) InputRow(org.apache.druid.data.input.InputRow) List(java.util.List) DimensionSchema(org.apache.druid.data.input.impl.DimensionSchema) DimFilter(org.apache.druid.query.filter.DimFilter) BitmapIndexSelector(org.apache.druid.query.filter.BitmapIndexSelector) Iterables(com.google.common.collect.Iterables) DoubleDimensionSchema(org.apache.druid.data.input.impl.DoubleDimensionSchema) Intervals(org.apache.druid.java.util.common.Intervals) FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) Parser(org.apache.druid.math.expr.Parser) SegmentWriteOutMediumFactory(org.apache.druid.segment.writeout.SegmentWriteOutMediumFactory) HashMap(java.util.HashMap) TimeAndDimsParseSpec(org.apache.druid.data.input.impl.TimeAndDimsParseSpec) ArrayList(java.util.ArrayList) VectorCursor(org.apache.druid.segment.vector.VectorCursor) ImmutableList(com.google.common.collect.ImmutableList) FloatDimensionSchema(org.apache.druid.data.input.impl.FloatDimensionSchema) IncrementalIndex(org.apache.druid.segment.incremental.IncrementalIndex) SettableSupplier(org.apache.druid.common.guava.SettableSupplier) VectorValueMatcher(org.apache.druid.query.filter.vector.VectorValueMatcher) RowBasedStorageAdapter(org.apache.druid.segment.RowBasedStorageAdapter) DimensionSelector(org.apache.druid.segment.DimensionSelector) VectorAggregator(org.apache.druid.query.aggregation.VectorAggregator) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) Sequences(org.apache.druid.java.util.common.guava.Sequences) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) SingleValueDimensionVectorSelector(org.apache.druid.segment.vector.SingleValueDimensionVectorSelector) Nullable(javax.annotation.Nullable) Before(org.junit.Before) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) BitmapResultFactory(org.apache.druid.query.BitmapResultFactory) ColumnInspector(org.apache.druid.segment.ColumnInspector) QueryableIndexStorageAdapter(org.apache.druid.segment.QueryableIndexStorageAdapter) VirtualColumns(org.apache.druid.segment.VirtualColumns) MapInputRowParser(org.apache.druid.data.input.impl.MapInputRowParser) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Aggregator(org.apache.druid.query.aggregation.Aggregator) Maps(com.google.common.collect.Maps) ColumnSelector(org.apache.druid.segment.ColumnSelector) Granularities(org.apache.druid.java.util.common.granularity.Granularities) BitmapSerdeFactory(org.apache.druid.segment.data.BitmapSerdeFactory) Rule(org.junit.Rule) Cursor(org.apache.druid.segment.Cursor) NullHandling(org.apache.druid.common.config.NullHandling) RowSignature(org.apache.druid.segment.column.RowSignature) Closeable(java.io.Closeable) ColumnType(org.apache.druid.segment.column.ColumnType) Preconditions(com.google.common.base.Preconditions) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) Filter(org.apache.druid.query.filter.Filter) IndexSpec(org.apache.druid.segment.IndexSpec) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) StorageAdapter(org.apache.druid.segment.StorageAdapter) IncrementalIndexStorageAdapter(org.apache.druid.segment.incremental.IncrementalIndexStorageAdapter) RowBasedStorageAdapter(org.apache.druid.segment.RowBasedStorageAdapter) QueryableIndexStorageAdapter(org.apache.druid.segment.QueryableIndexStorageAdapter) TmpFileSegmentWriteOutMediumFactory(org.apache.druid.segment.writeout.TmpFileSegmentWriteOutMediumFactory) OffHeapMemorySegmentWriteOutMediumFactory(org.apache.druid.segment.writeout.OffHeapMemorySegmentWriteOutMediumFactory) SegmentWriteOutMediumFactory(org.apache.druid.segment.writeout.SegmentWriteOutMediumFactory) Function(com.google.common.base.Function) RoaringBitmapSerdeFactory(org.apache.druid.segment.data.RoaringBitmapSerdeFactory) ConciseBitmapSerdeFactory(org.apache.druid.segment.data.ConciseBitmapSerdeFactory) IncrementalIndex(org.apache.druid.segment.incremental.IncrementalIndex) QueryableIndexStorageAdapter(org.apache.druid.segment.QueryableIndexStorageAdapter) IndexBuilder(org.apache.druid.segment.IndexBuilder) QueryableIndex(org.apache.druid.segment.QueryableIndex) IncrementalIndexStorageAdapter(org.apache.druid.segment.incremental.IncrementalIndexStorageAdapter) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ConciseBitmapSerdeFactory(org.apache.druid.segment.data.ConciseBitmapSerdeFactory) RoaringBitmapSerdeFactory(org.apache.druid.segment.data.RoaringBitmapSerdeFactory) BitmapSerdeFactory(org.apache.druid.segment.data.BitmapSerdeFactory)

Aggregations

BitmapSerdeFactory (org.apache.druid.segment.data.BitmapSerdeFactory)8 BitmapFactory (org.apache.druid.collections.bitmap.BitmapFactory)5 RoaringBitmapSerdeFactory (org.apache.druid.segment.data.RoaringBitmapSerdeFactory)5 Function (com.google.common.base.Function)4 MutableBitmap (org.apache.druid.collections.bitmap.MutableBitmap)4 RoaringBitmapFactory (org.apache.druid.collections.bitmap.RoaringBitmapFactory)4 BitmapIndex (org.apache.druid.segment.column.BitmapIndex)4 StringBitmapIndexColumnPartSupplier (org.apache.druid.segment.serde.StringBitmapIndexColumnPartSupplier)3 Setup (org.openjdk.jmh.annotations.Setup)3 Preconditions (com.google.common.base.Preconditions)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ImmutableBitmap (org.apache.druid.collections.bitmap.ImmutableBitmap)2 NullHandling (org.apache.druid.common.config.NullHandling)2 BitmapIndexSelector (org.apache.druid.query.filter.BitmapIndexSelector)2 DruidColumnHandle (com.facebook.presto.druid.DruidColumnHandle)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1