Skip to content

Commit

Permalink
Throw an error when all arguments are NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
normanj-bitquill committed Sep 10, 2024
1 parent ed0d0f2 commit 1976af2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ ExInst<SqlValidatorException> intervalFractionalSecondPrecisionOutOfRange(
@BaseMessage("Argument to function ''{0}'' must not be NULL")
ExInst<SqlValidatorException> argumentMustNotBeNull(String a0);

@BaseMessage("At least one argument to function ''{0}'' must not be NULL")
ExInst<SqlValidatorException> atLeastOneArgumentMustNotBeNull(String a0);

@BaseMessage("Illegal use of ''NULL''")
ExInst<SqlValidatorException> nullIllegal();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1201,23 +1201,23 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable {
*/
public static final SqlFunction BITAND =
SqlBasicFunction.create("BITAND", SqlKind.BITAND,
ReturnTypes.LARGEST_INT_OR_FIRST_NON_NULL_DEFAULT_INTEGER,
ReturnTypes.LARGEST_INT_OR_FIRST_NON_NULL,
OperandTypes.INTEGER_INTEGER.or(OperandTypes.BINARY_BINARY));

/**
* <code>BITOR</code> scalar function.
*/
public static final SqlFunction BITOR =
SqlBasicFunction.create("BITOR", SqlKind.BITOR,
ReturnTypes.LARGEST_INT_OR_FIRST_NON_NULL_DEFAULT_INTEGER,
ReturnTypes.LARGEST_INT_OR_FIRST_NON_NULL,
OperandTypes.INTEGER_INTEGER.or(OperandTypes.BINARY_BINARY));

/**
* <code>BITXOR</code> scalar function.
*/
public static final SqlFunction BITXOR =
SqlBasicFunction.create("BITXOR", SqlKind.BITXOR,
ReturnTypes.LARGEST_INT_OR_FIRST_NON_NULL_DEFAULT_INTEGER,
ReturnTypes.LARGEST_INT_OR_FIRST_NON_NULL,
OperandTypes.INTEGER_INTEGER.or(OperandTypes.BINARY_BINARY));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ public static SqlCall stripSeparator(SqlCall call) {
* As a fallback, choose the type of the first argument that is not of the NULL type.
* Nullable if at least one argument is nullable.
*/
public static final SqlReturnTypeInference LARGEST_INT_OR_FIRST_NON_NULL_DEFAULT_INTEGER =
public static final SqlReturnTypeInference LARGEST_INT_OR_FIRST_NON_NULL =
opBinding -> {
final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
RelDataType largestIntegerType = null;
Expand All @@ -646,8 +646,9 @@ public static SqlCall stripSeparator(SqlCall call) {
} else if (firstNonNullType != null) {
return typeFactory.createTypeWithNullability(firstNonNullType, nullable);
}
return typeFactory.createTypeWithNullability(
typeFactory.createSqlType(SqlTypeName.INTEGER), true);
throw opBinding.newError(
RESOURCE.atLeastOneArgumentMustNotBeNull(
opBinding.getOperator().getName()));
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ ArgumentMustBeNumericLiteralInRange=Argument to function ''{0}'' must be a numer
ValidationError=Validation Error: {0}
IllegalLocaleFormat=Locale ''{0}'' in an illegal format
ArgumentMustNotBeNull=Argument to function ''{0}'' must not be NULL
AtLeastOneArgumentMustNotBeNull=At least one argument to function ''{0}'' must not be NULL
NullIllegal=Illegal use of ''NULL''
DynamicParamIllegal=Illegal use of dynamic parameter
InvalidBoolean=''{0}'' is not a valid boolean value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15512,7 +15512,9 @@ private static void checkLogicalOrFunc(SqlOperatorFixture f) {
false);
f.checkNull("bitand(NULL, 1)");
f.checkNull("bitand(1, NULL)");
f.checkNull("bitand(NULL, NULL)");
f.checkFails("^bitand(NULL, NULL)^",
"At least one argument to function 'BITAND' must not be NULL",
false);
f.checkFails("bitand(CAST(x'0201' AS VARBINARY), CAST(x'02' AS VARBINARY))",
"Different length for bitwise operands: the first: 2, the second: 1",
true);
Expand Down Expand Up @@ -15552,7 +15554,9 @@ private static void checkLogicalOrFunc(SqlOperatorFixture f) {
false);
f.checkNull("bitor(NULL, 1)");
f.checkNull("bitor(1, NULL)");
f.checkNull("bitor(NULL, NULL)");
f.checkFails("^bitor(NULL, NULL)^",
"At least one argument to function 'BITOR' must not be NULL",
false);
f.checkFails("bitor(CAST(x'0201' AS VARBINARY), CAST(x'02' AS VARBINARY))",
"Different length for bitwise operands: the first: 2, the second: 1",
true);
Expand Down Expand Up @@ -15592,7 +15596,9 @@ private static void checkLogicalOrFunc(SqlOperatorFixture f) {
false);
f.checkNull("bitxor(NULL, 1)");
f.checkNull("bitxor(1, NULL)");
f.checkNull("bitxor(NULL, NULL)");
f.checkFails("^bitxor(NULL, NULL)^",
"At least one argument to function 'BITXOR' must not be NULL",
false);
f.checkFails("bitxor(CAST(x'0201' AS VARBINARY), CAST(x'02' AS VARBINARY))",
"Different length for bitwise operands: the first: 2, the second: 1",
true);
Expand Down

0 comments on commit 1976af2

Please sign in to comment.