Search in sources :

Example 1 with BitmapIndex

use of io.druid.segment.column.BitmapIndex in project druid by druid-io.

the class BoundFilterBenchmark method setup.

@Setup
public void setup() throws IOException {
    step = (END_INT - START_INT) / cardinality;
    final BitmapFactory bitmapFactory = new RoaringBitmapFactory();
    final BitmapSerdeFactory serdeFactory = new RoaringBitmapSerdeFactory(null);
    final List<Integer> ints = generateInts();
    final GenericIndexed<String> dictionary = GenericIndexed.fromIterable(FluentIterable.from(ints).transform(new Function<Integer, String>() {

        @Override
        public String apply(Integer i) {
            return i.toString();
        }
    }), GenericIndexed.STRING_STRATEGY);
    final BitmapIndex bitmapIndex = new BitmapIndexColumnPartSupplier(bitmapFactory, GenericIndexed.fromIterable(FluentIterable.from(ints).transform(new Function<Integer, ImmutableBitmap>() {

        @Override
        public ImmutableBitmap apply(Integer i) {
            final MutableBitmap mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
            mutableBitmap.add((i - START_INT) / step);
            return bitmapFactory.makeImmutableBitmap(mutableBitmap);
        }
    }), serdeFactory.getObjectStrategy()), dictionary).get();
    selector = new BitmapIndexSelector() {

        @Override
        public Indexed<String> getDimensionValues(String dimension) {
            return dictionary;
        }

        @Override
        public int getNumRows() {
            throw new UnsupportedOperationException();
        }

        @Override
        public BitmapFactory getBitmapFactory() {
            return bitmapFactory;
        }

        @Override
        public ImmutableBitmap getBitmapIndex(String dimension, String value) {
            return bitmapIndex.getBitmap(bitmapIndex.getIndex(value));
        }

        @Override
        public BitmapIndex getBitmapIndex(String dimension) {
            return bitmapIndex;
        }

        @Override
        public ImmutableRTree getSpatialIndex(String dimension) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) MutableBitmap(io.druid.collections.bitmap.MutableBitmap) BitmapIndex(io.druid.segment.column.BitmapIndex) Function(com.google.common.base.Function) ImmutableRTree(io.druid.collections.spatial.ImmutableRTree) RoaringBitmapSerdeFactory(io.druid.segment.data.RoaringBitmapSerdeFactory) BitmapIndexColumnPartSupplier(io.druid.segment.serde.BitmapIndexColumnPartSupplier) BitmapIndexSelector(io.druid.query.filter.BitmapIndexSelector) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Indexed(io.druid.segment.data.Indexed) GenericIndexed(io.druid.segment.data.GenericIndexed) RoaringBitmapSerdeFactory(io.druid.segment.data.RoaringBitmapSerdeFactory) BitmapSerdeFactory(io.druid.segment.data.BitmapSerdeFactory) Setup(org.openjdk.jmh.annotations.Setup)

Example 2 with BitmapIndex

use of io.druid.segment.column.BitmapIndex in project druid by druid-io.

the class QueryableIndexIndexableAdapter method getBitmapIndex.

@Override
public IndexedInts getBitmapIndex(String dimension, int dictId) {
    final Column column = input.getColumn(dimension);
    if (column == null) {
        return EmptyIndexedInts.EMPTY_INDEXED_INTS;
    }
    final BitmapIndex bitmaps = column.getBitmapIndex();
    if (bitmaps == null) {
        return EmptyIndexedInts.EMPTY_INDEXED_INTS;
    }
    if (dictId >= 0) {
        return new BitmapCompressedIndexedInts(bitmaps.getBitmap(dictId));
    } else {
        return EmptyIndexedInts.EMPTY_INDEXED_INTS;
    }
}
Also used : IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) GenericColumn(io.druid.segment.column.GenericColumn) ComplexColumn(io.druid.segment.column.ComplexColumn) Column(io.druid.segment.column.Column) DictionaryEncodedColumn(io.druid.segment.column.DictionaryEncodedColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) BitmapCompressedIndexedInts(io.druid.segment.data.BitmapCompressedIndexedInts) BitmapIndex(io.druid.segment.column.BitmapIndex)

Example 3 with BitmapIndex

use of io.druid.segment.column.BitmapIndex in project druid by druid-io.

the class QueryableIndexIndexableAdapter method getBitmapIndex.

@VisibleForTesting
IndexedInts getBitmapIndex(String dimension, String value) {
    final Column column = input.getColumn(dimension);
    if (column == null) {
        return EmptyIndexedInts.EMPTY_INDEXED_INTS;
    }
    final BitmapIndex bitmaps = column.getBitmapIndex();
    if (bitmaps == null) {
        return EmptyIndexedInts.EMPTY_INDEXED_INTS;
    }
    return new BitmapCompressedIndexedInts(bitmaps.getBitmap(bitmaps.getIndex(value)));
}
Also used : IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) GenericColumn(io.druid.segment.column.GenericColumn) ComplexColumn(io.druid.segment.column.ComplexColumn) Column(io.druid.segment.column.Column) DictionaryEncodedColumn(io.druid.segment.column.DictionaryEncodedColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) BitmapCompressedIndexedInts(io.druid.segment.data.BitmapCompressedIndexedInts) BitmapIndex(io.druid.segment.column.BitmapIndex) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with BitmapIndex

use of io.druid.segment.column.BitmapIndex in project druid by druid-io.

the class Filters method estimateSelectivity.

/**
   * Return an estimated selectivity for bitmaps of all values matching the given predicate.
   *
   * @param dimension     dimension to look at
   * @param indexSelector bitmap selector
   * @param predicate     predicate to use
   *
   * @return estimated selectivity
   *
   * @see #matchPredicate(String, BitmapIndexSelector, Predicate)
   */
public static double estimateSelectivity(final String dimension, final BitmapIndexSelector indexSelector, final Predicate<String> predicate) {
    Preconditions.checkNotNull(dimension, "dimension");
    Preconditions.checkNotNull(indexSelector, "selector");
    Preconditions.checkNotNull(predicate, "predicate");
    // Missing dimension -> match all rows if the predicate matches null; match no rows otherwise
    final Indexed<String> dimValues = indexSelector.getDimensionValues(dimension);
    if (dimValues == null || dimValues.size() == 0) {
        return predicate.apply(null) ? 1. : 0.;
    }
    // Apply predicate to all dimension values and union the matching bitmaps
    final BitmapIndex bitmapIndex = indexSelector.getBitmapIndex(dimension);
    return estimateSelectivity(bitmapIndex, IntIteratorUtils.toIntList(makePredicateQualifyingIndexIterable(bitmapIndex, predicate, dimValues).iterator()), indexSelector.getNumRows());
}
Also used : BitmapIndex(io.druid.segment.column.BitmapIndex)

Example 5 with BitmapIndex

use of io.druid.segment.column.BitmapIndex in project druid by druid-io.

the class LikeFilterBenchmark method setup.

@Setup
public void setup() throws IOException {
    step = (END_INT - START_INT) / cardinality;
    final BitmapFactory bitmapFactory = new RoaringBitmapFactory();
    final BitmapSerdeFactory serdeFactory = new RoaringBitmapSerdeFactory(null);
    final List<Integer> ints = generateInts();
    final GenericIndexed<String> dictionary = GenericIndexed.fromIterable(FluentIterable.from(ints).transform(new Function<Integer, String>() {

        @Override
        public String apply(Integer i) {
            return i.toString();
        }
    }), GenericIndexed.STRING_STRATEGY);
    final BitmapIndex bitmapIndex = new BitmapIndexColumnPartSupplier(bitmapFactory, GenericIndexed.fromIterable(FluentIterable.from(ints).transform(new Function<Integer, ImmutableBitmap>() {

        @Override
        public ImmutableBitmap apply(Integer i) {
            final MutableBitmap mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
            mutableBitmap.add((i - START_INT) / step);
            return bitmapFactory.makeImmutableBitmap(mutableBitmap);
        }
    }), serdeFactory.getObjectStrategy()), dictionary).get();
    selector = new BitmapIndexSelector() {

        @Override
        public Indexed<String> getDimensionValues(String dimension) {
            return dictionary;
        }

        @Override
        public int getNumRows() {
            throw new UnsupportedOperationException();
        }

        @Override
        public BitmapFactory getBitmapFactory() {
            return bitmapFactory;
        }

        @Override
        public ImmutableBitmap getBitmapIndex(String dimension, String value) {
            return bitmapIndex.getBitmap(bitmapIndex.getIndex(value));
        }

        @Override
        public BitmapIndex getBitmapIndex(String dimension) {
            return bitmapIndex;
        }

        @Override
        public ImmutableRTree getSpatialIndex(String dimension) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) MutableBitmap(io.druid.collections.bitmap.MutableBitmap) BitmapIndex(io.druid.segment.column.BitmapIndex) Function(com.google.common.base.Function) ImmutableRTree(io.druid.collections.spatial.ImmutableRTree) RoaringBitmapSerdeFactory(io.druid.segment.data.RoaringBitmapSerdeFactory) BitmapIndexColumnPartSupplier(io.druid.segment.serde.BitmapIndexColumnPartSupplier) BitmapIndexSelector(io.druid.query.filter.BitmapIndexSelector) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) BitmapFactory(io.druid.collections.bitmap.BitmapFactory) RoaringBitmapFactory(io.druid.collections.bitmap.RoaringBitmapFactory) Indexed(io.druid.segment.data.Indexed) GenericIndexed(io.druid.segment.data.GenericIndexed) RoaringBitmapSerdeFactory(io.druid.segment.data.RoaringBitmapSerdeFactory) BitmapSerdeFactory(io.druid.segment.data.BitmapSerdeFactory) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

BitmapIndex (io.druid.segment.column.BitmapIndex)12 BitmapFactory (io.druid.collections.bitmap.BitmapFactory)5 ImmutableBitmap (io.druid.collections.bitmap.ImmutableBitmap)5 MutableBitmap (io.druid.collections.bitmap.MutableBitmap)4 RoaringBitmapFactory (io.druid.collections.bitmap.RoaringBitmapFactory)4 Column (io.druid.segment.column.Column)4 BitmapSerdeFactory (io.druid.segment.data.BitmapSerdeFactory)4 RoaringBitmapSerdeFactory (io.druid.segment.data.RoaringBitmapSerdeFactory)4 Function (com.google.common.base.Function)3 ImmutableRTree (io.druid.collections.spatial.ImmutableRTree)3 BitmapIndexSelector (io.druid.query.filter.BitmapIndexSelector)3 DictionaryEncodedColumn (io.druid.segment.column.DictionaryEncodedColumn)3 GenericColumn (io.druid.segment.column.GenericColumn)3 GenericIndexed (io.druid.segment.data.GenericIndexed)3 Indexed (io.druid.segment.data.Indexed)3 BitmapIndexColumnPartSupplier (io.druid.segment.serde.BitmapIndexColumnPartSupplier)3 Setup (org.openjdk.jmh.annotations.Setup)3 ConciseBitmapFactory (io.druid.collections.bitmap.ConciseBitmapFactory)2 ComplexColumn (io.druid.segment.column.ComplexColumn)2 IndexedFloatsGenericColumn (io.druid.segment.column.IndexedFloatsGenericColumn)2