tanclary commented on code in PR #3236:
URL: https://github.com/apache/calcite/pull/3236#discussion_r1213406654


##########
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:
   Why do you need both `COLLECTIONS_SORT` and  `SORT_ARRAY`? From what I can 
see COLLECTIONS_SORT never gets used. Let me know if I'm misunderstanding.



##########
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:
   array should be *array*, Also I don't know if it's clear from this what the 
default behavior is if `ascendingOrder` is not specified. I think this could be 
made a little more clear.



##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -3061,6 +3063,28 @@ private static class ReinterpretImplementor extends 
AbstractRexCallImplementor {
     }
   }
 
+  /** Implementor for sort_array. */
+  private static class SortArrayImplementor extends AbstractRexCallImplementor 
{
+    SortArrayImplementor() {
+      super("sort_array", NullPolicy.STRICT, false);
+    }
+
+    @Override Expression implementSafe(RexToLixTranslator translator,
+        RexCall call, List<Expression> argValueList) {
+      if (argValueList.size() == 2) {
+        return Expressions.call(
+            BuiltInMethod.SORT_ARRAY.method,
+            argValueList.get(0),

Review Comment:
   Pretty sure if you're just passing the whole argValueList you don't need to 
retrieve each element individually, you can just do 
`.call(BuiltInMethod.SORT_ARRAY.method, argValueList);` The 
`LogicalNotImplementor` and `LogImplementor` are a couple of examples. 



##########
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:
   There's already a `BOOLEAN` entry in `OperandTypes`, what about this 
function necessitates the need for `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]

Reply via email to