Handling nil selector column in vector math processors (#16128)

This commit is contained in:
Sree Charan Manamala 2024-04-02 14:36:57 +05:30 committed by GitHub
parent 06268bf060
commit 26f9b174de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 22 deletions

View File

@ -241,7 +241,14 @@ public interface Function extends NamedFunction
@Override
public boolean canVectorize(Expr.InputBindingInspector inspector, List<Expr> args)
{
return inspector.areNumeric(args) && inspector.canVectorize(args);
// can not vectorize in default mode for 'missing' columns
// it creates inconsistencies as we default the output type to STRING, making the value null
// but the numeric columns expect a non null value
final ExpressionType outputType = args.get(0).getOutputType(inspector);
if (outputType == null && NullHandling.replaceWithDefault()) {
return false;
}
return (outputType == null || outputType.isNumeric()) && inspector.canVectorize(args);
}
}

View File

@ -47,13 +47,12 @@ public class VectorMathProcessors
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 (Types.isNullOr(inputType, ExprType.DOUBLE)) {
processor = doubleOutDoubleInSupplier.get();
} else if (inputType.is(ExprType.LONG)) {
processor = longOutLongInSupplier.get();
}
if (processor == null) {
throw Exprs.cannotVectorize();
}
@ -75,13 +74,12 @@ public class VectorMathProcessors
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 (Types.isNullOr(inputType, ExprType.DOUBLE)) {
processor = doubleOutDoubleInSupplier.get();
} else if (inputType.is(ExprType.LONG)) {
processor = doubleOutLongInSupplier.get();
}
if (processor == null) {
throw Exprs.cannotVectorize();
}
@ -103,13 +101,12 @@ public class VectorMathProcessors
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 = longOutDoubleInSupplier.get();
}
if (Types.isNullOr(inputType, ExprType.DOUBLE)) {
processor = longOutDoubleInSupplier.get();
} else if (inputType.is(ExprType.LONG)) {
processor = longOutLongInSupplier.get();
}
if (processor == null) {
throw Exprs.cannotVectorize();
}
@ -2035,7 +2032,7 @@ public class VectorMathProcessors
return Double.doubleToLongBits(input);
}
};
} else if (Types.is(inputType, ExprType.DOUBLE)) {
} else if (Types.isNullOr(inputType, ExprType.DOUBLE)) {
processor = new LongOutDoubleInFunctionVectorValueProcessor(
arg.asVectorProcessor(inspector),
inspector.getMaxVectorSize()
@ -2074,7 +2071,7 @@ public class VectorMathProcessors
return Double.longBitsToDouble(input);
}
};
} else if (Types.is(inputType, ExprType.DOUBLE)) {
} else if (Types.isNullOr(inputType, ExprType.DOUBLE)) {
processor = new DoubleOutDoubleInFunctionVectorValueProcessor(
arg.asVectorProcessor(inspector),
inspector.getMaxVectorSize()

View File

@ -176,7 +176,13 @@ public class VectorExprSanityTest extends InitializedNullHandlingTest
"bitwiseConvertDoubleToLongBits",
"bitwiseConvertLongBitsToDouble"
};
final String[] templates = new String[]{"%s(l1)", "%s(d1)", "%s(pi())", "%s(null)"};
final String[] templates;
if (NullHandling.sqlCompatible()) {
templates = new String[]{"%s(l1)", "%s(d1)", "%s(pi())", "%s(null)", "%s(missing)"};
} else {
// missing columns are not vectorizable in default value mode
templates = new String[]{"%s(l1)", "%s(d1)", "%s(pi())", "%s(null)"};
}
testFunctions(types, templates, functions);
}