liuyongvs commented on code in PR #3236:
URL: https://github.com/apache/calcite/pull/3236#discussion_r1213775021
##########
core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java:
##########
@@ -496,6 +496,71 @@ public static SqlOperandTypeChecker variadic(
public static final SqlSingleOperandTypeChecker LITERAL =
new LiteralOperandTypeChecker(false);
+ /**
+ * Operand type-checking strategy type must be a boolean non-NULL literal.
+ */
+ public static final SqlSingleOperandTypeChecker BOOLEAN_LITERAL =
+ new FamilyOperandTypeChecker(ImmutableList.of(SqlTypeFamily.BOOLEAN),
+ i -> false) {
+ @Override public boolean checkSingleOperandType(
+ SqlCallBinding callBinding,
+ SqlNode operand,
+ int iFormalOperand,
+ boolean throwOnFailure) {
+ if (!LITERAL.checkSingleOperandType(
+ callBinding,
+ operand,
+ iFormalOperand,
+ throwOnFailure)) {
+ return false;
+ }
+
+ if (!super.checkSingleOperandType(
+ callBinding,
+ operand,
+ iFormalOperand,
+ throwOnFailure)) {
+ return false;
+ }
+
+ final SqlLiteral arg = (SqlLiteral) operand;
+ final boolean isBooleanLiteral =
+ SqlLiteral.valueMatchesType(arg.getValue(), SqlTypeName.BOOLEAN);
+
+ if (!isBooleanLiteral) {
+ if (throwOnFailure) {
+ throw callBinding.newError(
+ RESOURCE.argumentMustBeBooleanLiteral(
+ callBinding.getOperator().getName()));
+ }
+ return false;
+ }
+ return true;
+ }
+ };
+
Review Comment:
@tanclary it is need, you can look the unit test i add , which will both
fail in spark
f.checkFails("^sort_array(array[2, null, 1], cast(1 as boolean))^",
"Argument to function 'SORT_ARRAY' must be a literal", false);
and sort_array(array[2, null, 1], b) , b is column
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]