Search in sources :

Example 1 with DruidPredicateFactory

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

the class ExpressionFilter method makeVectorMatcher.

@Override
public VectorValueMatcher makeVectorMatcher(VectorColumnSelectorFactory factory) {
    final Expr theExpr = expr.get();
    DruidPredicateFactory predicateFactory = new DruidPredicateFactory() {

        @Override
        public Predicate<String> makeStringPredicate() {
            return Evals::asBoolean;
        }

        @Override
        public DruidLongPredicate makeLongPredicate() {
            return Evals::asBoolean;
        }

        @Override
        public DruidFloatPredicate makeFloatPredicate() {
            return Evals::asBoolean;
        }

        @Override
        public DruidDoublePredicate makeDoublePredicate() {
            return Evals::asBoolean;
        }

        // The hashcode and equals are to make SubclassesMustOverrideEqualsAndHashCodeTest stop complaining..
        // DruidPredicateFactory currently doesn't really need equals or hashcode since 'toString' method that is actually
        // called when testing equality of DimensionPredicateFilter, so it's the truly required method, but that seems
        // a bit strange. DimensionPredicateFilter should probably be reworked to use equals from DruidPredicateFactory
        // instead of using toString.
        @Override
        public int hashCode() {
            return super.hashCode();
        }

        @Override
        public boolean equals(Object obj) {
            return super.equals(obj);
        }
    };
    final ExpressionType outputType = theExpr.getOutputType(factory);
    // effectively constant
    if (outputType == null) {
        // false matcher
        if (NullHandling.sqlCompatible()) {
            return BooleanVectorValueMatcher.of(factory.getReadableVectorInspector(), false);
        }
        // or not.
        return BooleanVectorValueMatcher.of(factory.getReadableVectorInspector(), theExpr.eval(InputBindings.nilBindings()).asBoolean());
    }
    // if we got here, we really have to evaluate the expressions to match
    switch(outputType.getType()) {
        case LONG:
            return VectorValueMatcherColumnProcessorFactory.instance().makeLongProcessor(ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.LONG), ExpressionVectorSelectors.makeVectorValueSelector(factory, theExpr)).makeMatcher(predicateFactory);
        case DOUBLE:
            return VectorValueMatcherColumnProcessorFactory.instance().makeDoubleProcessor(ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.DOUBLE), ExpressionVectorSelectors.makeVectorValueSelector(factory, theExpr)).makeMatcher(predicateFactory);
        case STRING:
            return VectorValueMatcherColumnProcessorFactory.instance().makeObjectProcessor(ColumnCapabilitiesImpl.createSimpleSingleValueStringColumnCapabilities(), ExpressionVectorSelectors.makeVectorObjectSelector(factory, theExpr)).makeMatcher(predicateFactory);
        default:
            throw new UOE("Vectorized expression matchers not implemented for type: [%s]", outputType);
    }
}
Also used : Expr(org.apache.druid.math.expr.Expr) UOE(org.apache.druid.java.util.common.UOE) ExpressionType(org.apache.druid.math.expr.ExpressionType) DruidPredicateFactory(org.apache.druid.query.filter.DruidPredicateFactory)

Aggregations

UOE (org.apache.druid.java.util.common.UOE)1 Expr (org.apache.druid.math.expr.Expr)1 ExpressionType (org.apache.druid.math.expr.ExpressionType)1 DruidPredicateFactory (org.apache.druid.query.filter.DruidPredicateFactory)1