Search in sources :

Example 21 with RuntimeShapeInspector

use of org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector in project druid by druid-io.

the class DimensionSelectorUtils method makeDictionaryEncodedValueMatcherGeneric.

private static ValueMatcher makeDictionaryEncodedValueMatcherGeneric(final DimensionSelector selector, Predicate<String> predicate) {
    final BitSet checkedIds = new BitSet(selector.getValueCardinality());
    final BitSet matchingIds = new BitSet(selector.getValueCardinality());
    final boolean matchNull = predicate.apply(null);
    // Lazy matcher; only check an id if matches() is called.
    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) {
                    final int id = row.get(i);
                    final boolean matches;
                    if (checkedIds.get(id)) {
                        matches = matchingIds.get(id);
                    } else {
                        matches = predicate.apply(selector.lookupName(id));
                        checkedIds.set(id);
                        if (matches) {
                            matchingIds.set(id);
                        }
                    }
                    if (matches) {
                        return true;
                    }
                }
                return false;
            }
        }

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

Example 22 with RuntimeShapeInspector

use of org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector 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 23 with RuntimeShapeInspector

use of org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector 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 24 with RuntimeShapeInspector

use of org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector 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 25 with RuntimeShapeInspector

use of org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector 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)

Aggregations

RuntimeShapeInspector (org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)26 ValueMatcher (org.apache.druid.query.filter.ValueMatcher)19 IndexedInts (org.apache.druid.segment.data.IndexedInts)11 BooleanValueMatcher (org.apache.druid.segment.filter.BooleanValueMatcher)8 Nullable (javax.annotation.Nullable)7 Predicate (com.google.common.base.Predicate)5 ArrayBasedIndexedInts (org.apache.druid.segment.data.ArrayBasedIndexedInts)5 BitSet (java.util.BitSet)4 IdLookup (org.apache.druid.segment.IdLookup)4 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)3 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)3 ColumnHolder (org.apache.druid.segment.column.ColumnHolder)3 Test (org.junit.Test)3 InputRow (org.apache.druid.data.input.InputRow)2 MapBasedInputRow (org.apache.druid.data.input.MapBasedInputRow)2 ISE (org.apache.druid.java.util.common.ISE)2 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)2 AbstractDimensionSelector (org.apache.druid.segment.AbstractDimensionSelector)2 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)2 RowBasedColumnSelectorFactory (org.apache.druid.segment.RowBasedColumnSelectorFactory)2