Search in sources :

Example 6 with ExpressionType

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

the class VectorMathProcessors method makeDoubleMathProcessor.

/**
 * Make a 1 argument math processor with the following type rules
 *    long    -> double
 *    double  -> double
 */
public static <T> ExprVectorProcessor<T> makeDoubleMathProcessor(Expr.VectorInputBindingInspector inspector, Expr arg, Supplier<DoubleOutLongInFunctionVectorValueProcessor> doubleOutLongInSupplier, Supplier<DoubleOutDoubleInFunctionVectorValueProcessor> doubleOutDoubleInSupplier) {
    final ExpressionType inputType = arg.getOutputType(inspector);
    ExprVectorProcessor<?> processor = null;
    if (inputType != null) {
        if (inputType.is(ExprType.LONG)) {
            processor = doubleOutLongInSupplier.get();
        } else if (inputType.is(ExprType.DOUBLE)) {
            processor = doubleOutDoubleInSupplier.get();
        }
    }
    if (processor == null) {
        throw Exprs.cannotVectorize();
    }
    return (ExprVectorProcessor<T>) processor;
}
Also used : ExpressionType(org.apache.druid.math.expr.ExpressionType)

Example 7 with ExpressionType

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

the class VectorMathProcessors method makeMathProcessor.

/**
 * Make a 1 argument math processor with the following type rules
 *    long    -> long
 *    double  -> double
 */
public static <T> ExprVectorProcessor<T> makeMathProcessor(Expr.VectorInputBindingInspector inspector, Expr arg, Supplier<LongOutLongInFunctionVectorValueProcessor> longOutLongInSupplier, Supplier<DoubleOutDoubleInFunctionVectorValueProcessor> doubleOutDoubleInSupplier) {
    final ExpressionType inputType = arg.getOutputType(inspector);
    ExprVectorProcessor<?> processor = null;
    if (inputType != null) {
        if (inputType.is(ExprType.LONG)) {
            processor = longOutLongInSupplier.get();
        } else if (inputType.is(ExprType.DOUBLE)) {
            processor = doubleOutDoubleInSupplier.get();
        }
    }
    if (processor == null) {
        throw Exprs.cannotVectorize();
    }
    return (ExprVectorProcessor<T>) processor;
}
Also used : ExpressionType(org.apache.druid.math.expr.ExpressionType)

Example 8 with ExpressionType

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

the class VectorMathProcessors method bitwiseConvertDoubleToLongBits.

public static <T> ExprVectorProcessor<T> bitwiseConvertDoubleToLongBits(Expr.VectorInputBindingInspector inspector, Expr arg) {
    final ExpressionType inputType = arg.getOutputType(inspector);
    ExprVectorProcessor<?> processor = null;
    if (Types.is(inputType, ExprType.LONG)) {
        processor = new LongOutLongInFunctionVectorValueProcessor(arg.buildVectorized(inspector), inspector.getMaxVectorSize()) {

            @Override
            public long apply(long input) {
                return Double.doubleToLongBits(input);
            }
        };
    } else if (Types.is(inputType, ExprType.DOUBLE)) {
        processor = new LongOutDoubleInFunctionVectorValueProcessor(arg.buildVectorized(inspector), inspector.getMaxVectorSize()) {

            @Override
            public long apply(double input) {
                return Double.doubleToLongBits(input);
            }
        };
    }
    if (processor == null) {
        throw Exprs.cannotVectorize();
    }
    return (ExprVectorProcessor<T>) processor;
}
Also used : ExpressionType(org.apache.druid.math.expr.ExpressionType)

Example 9 with ExpressionType

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

the class VectorMathProcessors method makeLongMathProcessor.

/**
 * Make a 2 argument, math processor with the following type rules
 *    long, long      -> long
 *    long, double    -> long
 *    double, long    -> long
 *    double, double  -> long
 */
public static <T> ExprVectorProcessor<T> makeLongMathProcessor(Expr.VectorInputBindingInspector inspector, Expr left, Expr right, Supplier<LongOutLongsInFunctionVectorValueProcessor> longOutLongsInProcessor, Supplier<LongOutLongDoubleInFunctionVectorValueProcessor> longOutLongDoubleInProcessor, Supplier<LongOutDoubleLongInFunctionVectorValueProcessor> longOutDoubleLongInProcessor, Supplier<LongOutDoublesInFunctionVectorValueProcessor> longOutDoublesInProcessor) {
    final ExpressionType leftType = left.getOutputType(inspector);
    final ExpressionType rightType = right.getOutputType(inspector);
    ExprVectorProcessor<?> processor = null;
    if (Types.is(leftType, ExprType.LONG)) {
        if (Types.isNullOr(rightType, ExprType.LONG)) {
            processor = longOutLongsInProcessor.get();
        } else if (rightType.is(ExprType.DOUBLE)) {
            processor = longOutLongDoubleInProcessor.get();
        }
    } else if (Types.is(leftType, ExprType.DOUBLE)) {
        if (Types.is(rightType, ExprType.LONG)) {
            processor = longOutDoubleLongInProcessor.get();
        } else if (Types.isNullOr(rightType, ExprType.DOUBLE)) {
            processor = longOutDoublesInProcessor.get();
        }
    } else if (leftType == null) {
        if (Types.is(rightType, ExprType.LONG)) {
            processor = longOutLongsInProcessor.get();
        } else if (Types.is(rightType, ExprType.DOUBLE)) {
            processor = longOutDoublesInProcessor.get();
        }
    }
    if (processor == null) {
        throw Exprs.cannotVectorize();
    }
    return (ExprVectorProcessor<T>) processor;
}
Also used : ExpressionType(org.apache.druid.math.expr.ExpressionType)

Example 10 with ExpressionType

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

the class Projection method postAggregatorDirectColumnIsOk.

/**
 * Returns true if a post-aggregation "expression" can be realized as a direct field access. This is true if it's
 * a direct column access that doesn't require an implicit cast.
 *
 * @param aggregateRowSignature signature of the aggregation
 * @param expression            post-aggregation expression
 * @param rexNode               RexNode for the post-aggregation expression
 *
 * @return yes or no
 */
private static boolean postAggregatorDirectColumnIsOk(final RowSignature aggregateRowSignature, final DruidExpression expression, final RexNode rexNode) {
    if (!expression.isDirectColumnAccess()) {
        return false;
    }
    // We don't really have a way to cast complex type. So might as well not do anything and return.
    final ColumnType columnValueType = aggregateRowSignature.getColumnType(expression.getDirectColumn()).orElseThrow(() -> new ISE("Encountered null type for column[%s]", expression.getDirectColumn()));
    if (columnValueType.is(ValueType.COMPLEX)) {
        return true;
    }
    // Check if a cast is necessary.
    final ExpressionType toExprType = ExpressionType.fromColumnTypeStrict(columnValueType);
    final ExpressionType fromExprType = ExpressionType.fromColumnTypeStrict(Calcites.getColumnTypeForRelDataType(rexNode.getType()));
    return toExprType.equals(fromExprType);
}
Also used : ColumnType(org.apache.druid.segment.column.ColumnType) ISE(org.apache.druid.java.util.common.ISE) 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