liuyongvs commented on code in PR #3236:
URL: https://github.com/apache/calcite/pull/3236#discussion_r1212507957
##########
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:
comments:
refers to NUMERIC_UNIT_INTERVAL_NUMERIC_LITERAL
the reason why i am not define the type like bellowing also is this
```
public static final SqlFunction SORT_ARRAY =
SqlBasicFunction.create(SqlKind.SORT_ARRAY,
ReturnTypes.ARG0_NULLABLE,
OperandTypes.ARRAY.or(
OperandTypes.sequence("'SORT_ARRAY(<ARRAY>, <BOOLEAN>)'",
OperandTypes.ARRAY, OperandTypes.BOOLEAN_LITERAL)));
```
--
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]