Search in sources :

Example 21 with ColumnSelectorFactory

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

the class BaseFilterTest method selectColumnValuesMatchingFilterUsingPostFiltering.

private List<String> selectColumnValuesMatchingFilterUsingPostFiltering(final DimFilter filter, final String selectColumn) {
    final Filter theFilter = makeFilter(filter);
    final Filter postFilteringFilter = new Filter() {

        @Override
        public <T> T getBitmapResult(BitmapIndexSelector selector, BitmapResultFactory<T> bitmapResultFactory) {
            throw new UnsupportedOperationException();
        }

        @Override
        public ValueMatcher makeMatcher(ColumnSelectorFactory factory) {
            return theFilter.makeMatcher(factory);
        }

        @Override
        public boolean supportsBitmapIndex(BitmapIndexSelector selector) {
            return false;
        }

        @Override
        public boolean shouldUseBitmapIndex(BitmapIndexSelector selector) {
            return false;
        }

        @Override
        public boolean supportsSelectivityEstimation(ColumnSelector columnSelector, BitmapIndexSelector indexSelector) {
            return false;
        }

        @Override
        public Set<String> getRequiredColumns() {
            return Collections.emptySet();
        }

        @Override
        public double estimateSelectivity(BitmapIndexSelector indexSelector) {
            return 1.0;
        }
    };
    final Sequence<Cursor> cursors = makeCursorSequence(postFilteringFilter);
    Sequence<List<String>> seq = Sequences.map(cursors, cursor -> {
        final DimensionSelector selector = cursor.getColumnSelectorFactory().makeDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
        final List<String> values = new ArrayList<>();
        while (!cursor.isDone()) {
            IndexedInts row = selector.getRow();
            Preconditions.checkState(row.size() == 1);
            values.add(selector.lookupName(row.get(0)));
            cursor.advance();
        }
        return values;
    });
    return seq.toList().get(0);
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) RowBasedColumnSelectorFactory(org.apache.druid.segment.RowBasedColumnSelectorFactory) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) ArrayList(java.util.ArrayList) VectorCursor(org.apache.druid.segment.vector.VectorCursor) Cursor(org.apache.druid.segment.Cursor) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) DimFilter(org.apache.druid.query.filter.DimFilter) Filter(org.apache.druid.query.filter.Filter) ColumnSelector(org.apache.druid.segment.ColumnSelector) IndexedInts(org.apache.druid.segment.data.IndexedInts) BitmapResultFactory(org.apache.druid.query.BitmapResultFactory) BitmapIndexSelector(org.apache.druid.query.filter.BitmapIndexSelector) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)21 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)10 Cursor (org.apache.druid.segment.Cursor)9 DimensionSelector (org.apache.druid.segment.DimensionSelector)8 Test (org.junit.Test)8 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)7 RowBasedColumnSelectorFactory (org.apache.druid.segment.RowBasedColumnSelectorFactory)7 List (java.util.List)6 IndexedInts (org.apache.druid.segment.data.IndexedInts)6 QueryableIndexStorageAdapter (org.apache.druid.segment.QueryableIndexStorageAdapter)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ByteBuffer (java.nio.ByteBuffer)4 Arrays (java.util.Arrays)4 Nullable (javax.annotation.Nullable)4 NullHandling (org.apache.druid.common.config.NullHandling)4 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)4 RuntimeShapeInspector (org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)4 BaseFloatColumnValueSelector (org.apache.druid.segment.BaseFloatColumnValueSelector)4 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)4 ValueType (org.apache.druid.segment.column.ValueType)4