Search in sources :

Example 46 with ExpressionType

use of org.apache.druid.math.expr.ExpressionType in project druid by apache.

the class VectorProcessors method makeSymmetricalProcessor.

/**
 * Make a 2 argument, symmetrical processor where both argments must be the same input type and produce the same
 * output type
 *    long, long      -> long
 *    double, double  -> double
 *    string, string  -> string
 */
public static <T> ExprVectorProcessor<T> makeSymmetricalProcessor(Expr.VectorInputBindingInspector inspector, Expr left, Expr right, Supplier<ExprVectorProcessor<?>> longProcessor, Supplier<ExprVectorProcessor<?>> doubleProcessor, Supplier<ExprVectorProcessor<?>> stringProcessor) {
    final ExpressionType leftType = left.getOutputType(inspector);
    if (leftType == null) {
        return right.buildVectorized(inspector);
    }
    Preconditions.checkArgument(inspector.areSameTypes(left, right));
    ExprVectorProcessor<?> processor = null;
    if (Types.is(leftType, ExprType.STRING)) {
        processor = stringProcessor.get();
    } else if (Types.is(leftType, ExprType.LONG)) {
        processor = longProcessor.get();
    } else if (Types.is(leftType, ExprType.DOUBLE)) {
        processor = doubleProcessor.get();
    }
    if (processor == null) {
        throw Exprs.cannotVectorize();
    }
    return (ExprVectorProcessor<T>) processor;
}
Also used : ExpressionType(org.apache.druid.math.expr.ExpressionType)

Aggregations

ExpressionType (org.apache.druid.math.expr.ExpressionType)46 Expr (org.apache.druid.math.expr.Expr)18 Nullable (javax.annotation.Nullable)6 ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)6 ArrayList (java.util.ArrayList)4 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)4 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)4 ColumnType (org.apache.druid.segment.column.ColumnType)4 VectorCursor (org.apache.druid.segment.vector.VectorCursor)4 VectorObjectSelector (org.apache.druid.segment.vector.VectorObjectSelector)4 VectorValueSelector (org.apache.druid.segment.vector.VectorValueSelector)4 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 IAE (org.apache.druid.java.util.common.IAE)2 ISE (org.apache.druid.java.util.common.ISE)2