Search in sources :

Example 51 with ValueMatcher

use of org.apache.druid.query.filter.ValueMatcher in project druid by druid-io.

the class DimensionSelectorUtils method makeNonDictionaryEncodedValueMatcherGeneric.

private static ValueMatcher makeNonDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, final Predicate<String> predicate) {
    final boolean matchNull = predicate.apply(null);
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            final IndexedInts row = selector.getRow();
            final int size = row.size();
            if (size == 0) {
                // null should match empty rows in multi-value columns
                return matchNull;
            } else {
                for (int i = 0; i < size; ++i) {
                    if (predicate.apply(selector.lookupName(row.get(i)))) {
                        return true;
                    }
                }
                return false;
            }
        }

        @Override
        public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
            inspector.visit("selector", selector);
            inspector.visit("predicate", predicate);
        }
    };
}
Also used : ValueMatcher(org.apache.druid.query.filter.ValueMatcher) BooleanValueMatcher(org.apache.druid.segment.filter.BooleanValueMatcher) IndexedInts(org.apache.druid.segment.data.IndexedInts) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)

Example 52 with ValueMatcher

use of org.apache.druid.query.filter.ValueMatcher in project druid by druid-io.

the class ValueMatchers method makeFloatValueMatcher.

/**
 * Creates a predicate-based {@link ValueMatcher} for a float-typed selector.
 *
 * @param selector         column selector
 * @param predicateFactory predicate to match
 */
public static ValueMatcher makeFloatValueMatcher(final BaseFloatColumnValueSelector selector, final DruidPredicateFactory predicateFactory) {
    final DruidFloatPredicate predicate = predicateFactory.makeFloatPredicate();
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            if (selector.isNull()) {
                return predicate.applyNull();
            }
            return predicate.applyFloat(selector.getFloat());
        }

        @Override
        public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
            inspector.visit("selector", selector);
            inspector.visit("predicate", predicate);
        }
    };
}
Also used : DruidFloatPredicate(org.apache.druid.query.filter.DruidFloatPredicate) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)

Example 53 with ValueMatcher

use of org.apache.druid.query.filter.ValueMatcher in project druid by druid-io.

the class ValueMatchers method makeDoubleValueMatcher.

/**
 * Creates a predicate-based {@link ValueMatcher} for a double-typed selector.
 *
 * @param selector         column selector
 * @param predicateFactory predicate to match
 */
public static ValueMatcher makeDoubleValueMatcher(final BaseDoubleColumnValueSelector selector, final DruidPredicateFactory predicateFactory) {
    final DruidDoublePredicate predicate = predicateFactory.makeDoublePredicate();
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            if (selector.isNull()) {
                return predicate.applyNull();
            }
            return predicate.applyDouble(selector.getDouble());
        }

        @Override
        public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
            inspector.visit("selector", selector);
            inspector.visit("predicate", predicate);
        }
    };
}
Also used : ValueMatcher(org.apache.druid.query.filter.ValueMatcher) DruidDoublePredicate(org.apache.druid.query.filter.DruidDoublePredicate) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)

Example 54 with ValueMatcher

use of org.apache.druid.query.filter.ValueMatcher in project druid by druid-io.

the class ValueMatchers method makeLongValueMatcher.

public static ValueMatcher makeLongValueMatcher(final BaseLongColumnValueSelector selector, final DruidPredicateFactory predicateFactory) {
    final DruidLongPredicate predicate = predicateFactory.makeLongPredicate();
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            if (selector.isNull()) {
                return predicate.applyNull();
            }
            return predicate.applyLong(selector.getLong());
        }

        @Override
        public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
            inspector.visit("selector", selector);
            inspector.visit("predicate", predicate);
        }
    };
}
Also used : ValueMatcher(org.apache.druid.query.filter.ValueMatcher) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector) DruidLongPredicate(org.apache.druid.query.filter.DruidLongPredicate)

Example 55 with ValueMatcher

use of org.apache.druid.query.filter.ValueMatcher in project druid by druid-io.

the class OrFilter method makeMatcher.

@Override
public ValueMatcher makeMatcher(BitmapIndexSelector selector, ColumnSelectorFactory columnSelectorFactory, RowOffsetMatcherFactory rowOffsetMatcherFactory) {
    final List<ValueMatcher> matchers = new ArrayList<>();
    final List<ImmutableBitmap> bitmaps = new ArrayList<>();
    for (Filter filter : filters) {
        if (filter.supportsBitmapIndex(selector)) {
            bitmaps.add(filter.getBitmapIndex(selector));
        } else {
            ValueMatcher matcher = filter.makeMatcher(columnSelectorFactory);
            matchers.add(matcher);
        }
    }
    if (bitmaps.size() > 0) {
        ImmutableBitmap combinedBitmap = selector.getBitmapFactory().union(bitmaps);
        ValueMatcher offsetMatcher = rowOffsetMatcherFactory.makeRowOffsetMatcher(combinedBitmap);
        matchers.add(0, offsetMatcher);
    }
    return makeMatcher(matchers.toArray(BooleanFilter.EMPTY_VALUE_MATCHER_ARRAY));
}
Also used : ValueMatcher(org.apache.druid.query.filter.ValueMatcher) BaseVectorValueMatcher(org.apache.druid.query.filter.vector.BaseVectorValueMatcher) VectorValueMatcher(org.apache.druid.query.filter.vector.VectorValueMatcher) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) BooleanFilter(org.apache.druid.query.filter.BooleanFilter) Filter(org.apache.druid.query.filter.Filter) ArrayList(java.util.ArrayList)

Aggregations

ValueMatcher (org.apache.druid.query.filter.ValueMatcher)59 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)33 Test (org.junit.Test)33 RuntimeShapeInspector (org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)19 IndexedInts (org.apache.druid.segment.data.IndexedInts)11 BooleanValueMatcher (org.apache.druid.segment.filter.BooleanValueMatcher)9 VectorValueMatcher (org.apache.druid.query.filter.vector.VectorValueMatcher)7 BaseVectorValueMatcher (org.apache.druid.query.filter.vector.BaseVectorValueMatcher)6 ArrayList (java.util.ArrayList)5 BitSet (java.util.BitSet)5 Nullable (javax.annotation.Nullable)5 Filter (org.apache.druid.query.filter.Filter)5 DimensionSelector (org.apache.druid.segment.DimensionSelector)5 ArrayBasedIndexedInts (org.apache.druid.segment.data.ArrayBasedIndexedInts)5 Predicate (com.google.common.base.Predicate)4 IdLookup (org.apache.druid.segment.IdLookup)4 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)3 BooleanFilter (org.apache.druid.query.filter.BooleanFilter)3 ConstantDimensionSelector (org.apache.druid.segment.ConstantDimensionSelector)3 ConstantMultiValueDimensionSelector (org.apache.druid.segment.ConstantMultiValueDimensionSelector)3