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 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
##########
core/src/main/java/org/apache/calcite/util/BuiltInMethod.java:
##########
@@ -308,6 +308,7 @@ public enum BuiltInMethod {
COLLECTIONS_REVERSE_ORDER(Collections.class, "reverseOrder"),
COLLECTIONS_EMPTY_LIST(Collections.class, "emptyList"),
COLLECTIONS_SINGLETON_LIST(Collections.class, "singletonList", Object.class),
+ COLLECTIONS_SORT(Collections.class, "sort", List.class, Comparator.class),
Review Comment:
it doesn't need, i will remove it
##########
site/_docs/reference.md:
##########
@@ -2658,6 +2658,7 @@ BigQuery's type system uses confusingly different names
for types and functions:
| s | ARRAY_REPEAT(element, count) | Returns the array
containing element count times.
| b | ARRAY_REVERSE(array) | Reverses elements of
*array*
| s | ARRAY_SIZE(array) | Synonym for
`CARDINALITY`
+| s | SORT_ARRAY(array [, ascendingOrder]) | Sorts the input array
in ascending or descending order according to the natural ordering of the array
elements. Null elements will be placed at the beginning of the returned array
in ascending order or at the end of the returned array in descending order
Review Comment:
add in the doc @tanclary
--
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]