use of org.apache.druid.math.expr.ExpressionType in project druid by apache.
the class VectorProcessors method isNull.
public static <T> ExprVectorProcessor<T> isNull(Expr.VectorInputBindingInspector inspector, Expr expr) {
final ExpressionType type = expr.getOutputType(inspector);
if (type == null) {
return constant(1L, 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] = 1L;
} else {
outputValues[i] = 0L;
}
}
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, 0L);
} else {
for (int i = 0; i < currentSize; i++) {
if (nulls[i]) {
outputValues[i] = 1L;
} else {
outputValues[i] = 0L;
}
}
}
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, 0L);
} else {
for (int i = 0; i < currentSize; i++) {
if (nulls[i]) {
outputValues[i] = 1L;
} else {
outputValues[i] = 0L;
}
}
}
return new ExprEvalLongVector(outputValues, null);
}
@Override
public ExpressionType getOutputType() {
return ExpressionType.LONG;
}
};
}
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 not.
public static <T> ExprVectorProcessor<T> not(Expr.VectorInputBindingInspector inspector, Expr expr) {
final ExpressionType inputType = expr.getOutputType(inspector);
final int maxVectorSize = inspector.getMaxVectorSize();
ExprVectorProcessor<?> processor = null;
if (Types.is(inputType, ExprType.STRING)) {
processor = new LongOutStringInFunctionVectorProcessor(expr.buildVectorized(inspector), maxVectorSize) {
@Override
public void processIndex(String[] strings, long[] longs, boolean[] outputNulls, int i) {
outputNulls[i] = strings[i] == null;
if (!outputNulls[i]) {
longs[i] = Evals.asLong(!Evals.asBoolean(strings[i]));
}
}
};
} else if (Types.is(inputType, ExprType.LONG)) {
processor = new LongOutLongInFunctionVectorValueProcessor(expr.buildVectorized(inspector), maxVectorSize) {
@Override
public long apply(long input) {
return Evals.asLong(!Evals.asBoolean(input));
}
};
} else if (Types.is(inputType, ExprType.DOUBLE)) {
if (!ExpressionProcessing.useStrictBooleans()) {
processor = new DoubleOutDoubleInFunctionVectorValueProcessor(expr.buildVectorized(inspector), maxVectorSize) {
@Override
public double apply(double input) {
return Evals.asDouble(!Evals.asBoolean(input));
}
};
} else {
processor = new LongOutDoubleInFunctionVectorValueProcessor(expr.buildVectorized(inspector), maxVectorSize) {
@Override
public long apply(double input) {
return Evals.asLong(!Evals.asBoolean(input));
}
};
}
}
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 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 apache.
the class VectorMathProcessors method bitwiseConvertLongBitsToDouble.
public static <T> ExprVectorProcessor<T> bitwiseConvertLongBitsToDouble(Expr.VectorInputBindingInspector inspector, Expr arg) {
final ExpressionType inputType = arg.getOutputType(inspector);
ExprVectorProcessor<?> processor = null;
if (Types.is(inputType, ExprType.LONG)) {
processor = new DoubleOutLongInFunctionVectorValueProcessor(arg.buildVectorized(inspector), inspector.getMaxVectorSize()) {
@Override
public double apply(long input) {
return Double.longBitsToDouble(input);
}
};
} else if (Types.is(inputType, ExprType.DOUBLE)) {
processor = new DoubleOutDoubleInFunctionVectorValueProcessor(arg.buildVectorized(inspector), inspector.getMaxVectorSize()) {
@Override
public double apply(double input) {
return Double.longBitsToDouble((long) 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 VectorComparisonProcessors method makeComparisonProcessor.
@Deprecated
public static <T> ExprVectorProcessor<T> makeComparisonProcessor(Expr.VectorInputBindingInspector inspector, Expr left, Expr right, Supplier<LongOutStringsInFunctionVectorProcessor> longOutStringsInFunctionVectorProcessor, Supplier<LongOutLongsInFunctionVectorValueProcessor> longOutLongsInProcessor, Supplier<DoubleOutLongDoubleInFunctionVectorValueProcessor> doubleOutLongDoubleInProcessor, Supplier<DoubleOutDoubleLongInFunctionVectorValueProcessor> doubleOutDoubleLongInProcessor, Supplier<DoubleOutDoublesInFunctionVectorValueProcessor> doubleOutDoublesInProcessor) {
assert !ExpressionProcessing.useStrictBooleans();
final ExpressionType leftType = left.getOutputType(inspector);
final ExpressionType rightType = right.getOutputType(inspector);
ExprVectorProcessor<?> processor = null;
if (Types.is(leftType, ExprType.STRING)) {
if (Types.isNullOr(rightType, ExprType.STRING)) {
processor = longOutStringsInFunctionVectorProcessor.get();
} else {
processor = doubleOutDoublesInProcessor.get();
}
} else if (leftType == null) {
if (Types.isNullOr(rightType, ExprType.STRING)) {
processor = longOutStringsInFunctionVectorProcessor.get();
}
} else if (leftType.is(ExprType.DOUBLE) || Types.is(rightType, ExprType.DOUBLE)) {
processor = doubleOutDoublesInProcessor.get();
}
if (processor != null) {
return (ExprVectorProcessor<T>) processor;
}
// fall through to normal math processor logic
return VectorMathProcessors.makeMathProcessor(inspector, left, right, longOutLongsInProcessor, doubleOutLongDoubleInProcessor, doubleOutDoubleLongInProcessor, doubleOutDoublesInProcessor);
}
Aggregations