Search in sources :

Example 61 with IndexedInts

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

the class MultiValueStringVectorValueMatcher method makeMatcher.

@Override
public VectorValueMatcher makeMatcher(@Nullable final String value) {
    final String etnValue = NullHandling.emptyToNullIfNeeded(NullHandling.emptyToNullIfNeeded(value));
    final IdLookup idLookup = selector.idLookup();
    final int id;
    if (idLookup != null) {
        // Optimization when names can be looked up to IDs ahead of time.
        id = idLookup.lookupId(etnValue);
        if (id < 0) {
            // Value doesn't exist in this column.
            return BooleanVectorValueMatcher.of(selector, false);
        }
        // Check for "id".
        return new BaseVectorValueMatcher(selector) {

            final VectorMatch match = VectorMatch.wrap(new int[selector.getMaxVectorSize()]);

            @Override
            public ReadableVectorMatch match(final ReadableVectorMatch mask) {
                final IndexedInts[] vector = selector.getRowVector();
                final int[] selection = match.getSelection();
                int numRows = 0;
                for (int i = 0; i < mask.getSelectionSize(); i++) {
                    final int rowNum = mask.getSelection()[i];
                    final IndexedInts ints = vector[rowNum];
                    final int n = ints.size();
                    if (n == 0) {
                        // null should match empty rows in multi-value columns
                        if (etnValue == null) {
                            selection[numRows++] = rowNum;
                        }
                    } else {
                        for (int j = 0; j < n; j++) {
                            if (ints.get(j) == id) {
                                selection[numRows++] = rowNum;
                                break;
                            }
                        }
                    }
                }
                match.setSelectionSize(numRows);
                assert match.isValid(mask);
                return match;
            }
        };
    } else {
        return makeMatcher(s -> Objects.equals(s, etnValue));
    }
}
Also used : IdLookup(org.apache.druid.segment.IdLookup) IndexedInts(org.apache.druid.segment.data.IndexedInts)

Example 62 with IndexedInts

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

the class CardinalityVectorAggregatorTest method testAggregateMultiValueString.

@Test
public void testAggregateMultiValueString() {
    final IndexedInts[] ids = { new ArrayBasedIndexedInts(new int[] { 1, 2 }), new ArrayBasedIndexedInts(new int[] { 2, 3 }), new ArrayBasedIndexedInts(new int[] { 3, 3 }), new ArrayBasedIndexedInts(new int[] { 0 }) };
    final String[] dict = { null, "abc", "def", "foo" };
    final CardinalityVectorAggregator aggregator = new CardinalityVectorAggregator(Collections.singletonList(new MultiValueStringCardinalityVectorProcessor(new MultiValueDimensionVectorSelector() {

        @Override
        public IndexedInts[] getRowVector() {
            return ids;
        }

        @Override
        public int getValueCardinality() {
            return dict.length;
        }

        @Nullable
        @Override
        public String lookupName(int id) {
            return dict[id];
        }

        @Override
        public boolean nameLookupPossibleInAdvance() {
            return true;
        }

        @Nullable
        @Override
        public IdLookup idLookup() {
            return null;
        }

        @Override
        public int getMaxVectorSize() {
            return ids.length;
        }

        @Override
        public int getCurrentVectorSize() {
            return ids.length;
        }
    })));
    testAggregate(aggregator, ids.length, NullHandling.replaceWithDefault() ? 4 : 3);
}
Also used : IdLookup(org.apache.druid.segment.IdLookup) MultiValueDimensionVectorSelector(org.apache.druid.segment.vector.MultiValueDimensionVectorSelector) ArrayBasedIndexedInts(org.apache.druid.segment.data.ArrayBasedIndexedInts) MultiValueStringCardinalityVectorProcessor(org.apache.druid.query.aggregation.cardinality.vector.MultiValueStringCardinalityVectorProcessor) IndexedInts(org.apache.druid.segment.data.IndexedInts) ArrayBasedIndexedInts(org.apache.druid.segment.data.ArrayBasedIndexedInts) Nullable(javax.annotation.Nullable) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 63 with IndexedInts

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

IndexedInts (org.apache.druid.segment.data.IndexedInts)63 DimensionSelector (org.apache.druid.segment.DimensionSelector)22 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)14 Test (org.junit.Test)13 RuntimeShapeInspector (org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)12 ArrayBasedIndexedInts (org.apache.druid.segment.data.ArrayBasedIndexedInts)12 Cursor (org.apache.druid.segment.Cursor)10 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)8 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)7 Predicate (com.google.common.base.Predicate)6 ByteBuffer (java.nio.ByteBuffer)6 Nullable (javax.annotation.Nullable)6 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)6 BooleanValueMatcher (org.apache.druid.segment.filter.BooleanValueMatcher)6 List (java.util.List)5 Predicates (com.google.common.base.Predicates)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Arrays (java.util.Arrays)4 NullHandling (org.apache.druid.common.config.NullHandling)4 MapBasedInputRow (org.apache.druid.data.input.MapBasedInputRow)4