mihaibudiu commented on code in PR #3579:
URL: https://github.com/apache/calcite/pull/3579#discussion_r1427013786


##########
core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java:
##########
@@ -1225,6 +1229,64 @@ private static class MapFromEntriesOperandTypeChecker
     }
   }
 
+  /**
+   * Operand type-checking strategy for a ARRAY function, it allows empty 
array.
+   *
+   * <p> The reason it overrides SameOperandTypeChecker#checkOperandTypesImpl 
is that it needs
+   * to handle the scenario where row/struct type and NULL exist 
simultaneously in array.
+   * This scenario need be supported, but will be rejected by the current 
checkOperandTypesImpl.

Review Comment:
   I think the last row of this comment should be removed. This would be 
appropriate in the PR, but not in a comment.



##########
core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java:
##########
@@ -1225,6 +1229,64 @@ private static class MapFromEntriesOperandTypeChecker
     }
   }
 
+  /**
+   * Operand type-checking strategy for a ARRAY function, it allows empty 
array.
+   *
+   * <p> The reason it overrides SameOperandTypeChecker#checkOperandTypesImpl 
is that it needs
+   * to handle the scenario where row/struct type and NULL exist 
simultaneously in array.
+   * This scenario need be supported, but will be rejected by the current 
checkOperandTypesImpl.
+   */
+  private static class ArrayFunctionOperandTypeChecker
+      extends SameOperandTypeChecker {
+
+    ArrayFunctionOperandTypeChecker() {
+      // The args of array are non-fixed, so we set to -1 here. then 
operandCount
+      // can dynamically set according to the number of input args.
+      // details please see SameOperandTypeChecker#getOperandList.
+      super(-1);
+    }
+
+    @Override protected boolean checkOperandTypesImpl(
+        SqlOperatorBinding operatorBinding,
+        boolean throwOnFailure,
+        @Nullable SqlCallBinding callBinding) {
+      if (throwOnFailure && callBinding == null) {
+        throw new IllegalArgumentException(
+            "callBinding must be non-null in case throwOnFailure=true");
+      }
+      int nOperandsActual = nOperands;
+      if (nOperandsActual == -1) {
+        nOperandsActual = operatorBinding.getOperandCount();
+      }
+      RelDataType[] types = new RelDataType[nOperandsActual];
+      final List<Integer> operandList =
+          getOperandList(operatorBinding.getOperandCount());
+      for (int i : operandList) {
+        types[i] = operatorBinding.getOperandType(i);
+      }
+      int prev = -1;
+      for (int i : operandList) {
+        if (prev >= 0) {

Review Comment:
   Can't this be replaced with `i > 0`?



-- 
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