use of org.apache.druid.math.expr.ExpressionType in project druid by apache.
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 apache.
the class VectorMathProcessors method makeMathProcessor.
/**
* Make a 2 argument, math processor with the following type rules
* long, long -> long
* long, double -> double
* double, long -> double
* double, double -> double
*/
public static <T> ExprVectorProcessor<T> makeMathProcessor(Expr.VectorInputBindingInspector inspector, Expr left, Expr right, Supplier<LongOutLongsInFunctionVectorValueProcessor> longOutLongsInProcessor, Supplier<DoubleOutLongDoubleInFunctionVectorValueProcessor> doubleOutLongDoubleInProcessor, Supplier<DoubleOutDoubleLongInFunctionVectorValueProcessor> doubleOutDoubleLongInProcessor, Supplier<DoubleOutDoublesInFunctionVectorValueProcessor> doubleOutDoublesInProcessor) {
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.anyOf(ExprType.STRING, ExprType.DOUBLE)) {
processor = doubleOutLongDoubleInProcessor.get();
}
} else if (Types.is(leftType, ExprType.DOUBLE)) {
if (Types.is(rightType, ExprType.LONG)) {
processor = doubleOutDoubleLongInProcessor.get();
} else if (Types.isNullOrAnyOf(rightType, ExprType.STRING, ExprType.DOUBLE)) {
processor = doubleOutDoublesInProcessor.get();
}
} else if (leftType == null) {
if (Types.is(rightType, ExprType.LONG)) {
processor = longOutLongsInProcessor.get();
} else if (Types.is(rightType, ExprType.DOUBLE)) {
processor = doubleOutLongDoubleInProcessor.get();
} else if (rightType == null) {
processor = longOutLongsInProcessor.get();
}
} else if (leftType.is(ExprType.STRING)) {
if (Types.is(rightType, ExprType.LONG)) {
processor = longOutLongsInProcessor.get();
} else if (Types.is(rightType, ExprType.DOUBLE)) {
processor = doubleOutLongDoubleInProcessor.get();
}
}
if (processor == null) {
throw Exprs.cannotVectorize(StringUtils.format("%s %s", leftType, rightType));
}
return (ExprVectorProcessor<T>) processor;
}
use of org.apache.druid.math.expr.ExpressionType in project druid by apache.
the class VectorMathProcessors method makeDoubleMathProcessor.
/**
* Make a 2 argument, math processor with the following type rules
* long, long -> double
* long, double -> double
* double, long -> double
* double, double -> double
*/
public static <T> ExprVectorProcessor<T> makeDoubleMathProcessor(Expr.VectorInputBindingInspector inspector, Expr left, Expr right, Supplier<DoubleOutLongsInFunctionVectorValueProcessor> doubleOutLongsInProcessor, Supplier<DoubleOutLongDoubleInFunctionVectorValueProcessor> doubleOutLongDoubleInProcessor, Supplier<DoubleOutDoubleLongInFunctionVectorValueProcessor> doubleOutDoubleLongInProcessor, Supplier<DoubleOutDoublesInFunctionVectorValueProcessor> doubleOutDoublesInProcessor) {
final ExpressionType leftType = left.getOutputType(inspector);
final ExpressionType rightType = right.getOutputType(inspector);
ExprVectorProcessor<?> processor = null;
if (Types.is(leftType, ExprType.LONG)) {
if (Types.is(rightType, ExprType.LONG)) {
processor = doubleOutLongsInProcessor.get();
} else if (Types.isNullOr(rightType, ExprType.DOUBLE)) {
processor = doubleOutLongDoubleInProcessor.get();
}
} else if (Types.is(leftType, ExprType.DOUBLE)) {
if (Types.is(rightType, ExprType.LONG)) {
processor = doubleOutDoubleLongInProcessor.get();
} else if (Types.isNullOr(rightType, ExprType.DOUBLE)) {
processor = doubleOutDoublesInProcessor.get();
}
} else if (leftType == null) {
if (Types.is(rightType, ExprType.LONG)) {
processor = doubleOutDoubleLongInProcessor.get();
} else if (Types.is(rightType, ExprType.DOUBLE)) {
processor = doubleOutDoublesInProcessor.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 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 VectorProcessors method isNotNull.
public static <T> ExprVectorProcessor<T> isNotNull(Expr.VectorInputBindingInspector inspector, Expr expr) {
final ExpressionType type = expr.getOutputType(inspector);
if (type == null) {
return constant(0L, inspector.getMaxVectorSize());
}
final long[] outputValues = new long[inspector.getMaxVectorSize()];
ExprVectorProcessor<?> processor = null;
if (Types.is(type, ExprType.STRING)) {
final ExprVectorProcessor<String[]> input = expr.buildVectorized(inspector);
processor = new ExprVectorProcessor<long[]>() {
@Override
public ExprEvalVector<long[]> evalVector(Expr.VectorInputBinding bindings) {
final ExprEvalVector<String[]> inputEval = input.evalVector(bindings);
final int currentSize = bindings.getCurrentVectorSize();
final String[] values = inputEval.values();
for (int i = 0; i < currentSize; i++) {
if (values[i] == null) {
outputValues[i] = 0L;
} else {
outputValues[i] = 1L;
}
}
return new ExprEvalLongVector(outputValues, null);
}
@Override
public ExpressionType getOutputType() {
return ExpressionType.LONG;
}
};
} else if (Types.is(type, ExprType.LONG)) {
final ExprVectorProcessor<long[]> input = expr.buildVectorized(inspector);
processor = new ExprVectorProcessor<long[]>() {
@Override
public ExprEvalVector<long[]> evalVector(Expr.VectorInputBinding bindings) {
final ExprEvalVector<long[]> inputEval = input.evalVector(bindings);
final int currentSize = bindings.getCurrentVectorSize();
final boolean[] nulls = inputEval.getNullVector();
if (nulls == null) {
Arrays.fill(outputValues, 1L);
} else {
for (int i = 0; i < currentSize; i++) {
if (nulls[i]) {
outputValues[i] = 0L;
} else {
outputValues[i] = 1L;
}
}
}
return new ExprEvalLongVector(outputValues, null);
}
@Override
public ExpressionType getOutputType() {
return ExpressionType.LONG;
}
};
} else if (Types.is(type, ExprType.DOUBLE)) {
final ExprVectorProcessor<double[]> input = expr.buildVectorized(inspector);
processor = new ExprVectorProcessor<long[]>() {
@Override
public ExprEvalVector<long[]> evalVector(Expr.VectorInputBinding bindings) {
final ExprEvalVector<double[]> inputEval = input.evalVector(bindings);
final int currentSize = bindings.getCurrentVectorSize();
final boolean[] nulls = inputEval.getNullVector();
if (nulls == null) {
Arrays.fill(outputValues, 1L);
} else {
for (int i = 0; i < currentSize; i++) {
if (nulls[i]) {
outputValues[i] = 0L;
} else {
outputValues[i] = 1L;
}
}
}
return new ExprEvalLongVector(outputValues, null);
}
@Override
public ExpressionType getOutputType() {
return ExpressionType.LONG;
}
};
}
if (processor == null) {
throw Exprs.cannotVectorize();
}
return (ExprVectorProcessor<T>) processor;
}
Aggregations