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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations