This is an automated email from the ASF dual-hosted git repository.

taoran pushed a commit to branch revert-3579-CALCITE-6127
in repository https://gitbox.apache.org/repos/asf/calcite.git

commit 32d40f47ff61129c48fd76ce5b896d9dcace26e3
Author: Ran Tao <chucheng...@gmail.com>
AuthorDate: Mon Dec 18 16:15:59 2023 +0800

    Revert "Handle code-reviews"
    
    This reverts commit 93c62ba225ffc6f3c4a6e7c71c1e81b8df716e35.
---
 .../main/java/org/apache/calcite/sql/type/OperandTypes.java    | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java 
b/core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java
index 8abb7c8178..6d4228d1f8 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java
@@ -1231,6 +1231,10 @@ public abstract class OperandTypes {
 
   /**
    * 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 {
@@ -1260,14 +1264,15 @@ public abstract class OperandTypes {
       for (int i : operandList) {
         types[i] = operatorBinding.getOperandType(i);
       }
+      int prev = -1;
       for (int i : operandList) {
-        if (i > 0) {
+        if (prev >= 0) {
           // we replace SqlTypeUtil.isComparable with 
SqlTypeUtil.leastRestrictiveForComparison
           // to handle struct type and NULL constant.
           // details please see: 
https://issues.apache.org/jira/browse/CALCITE-6163
           RelDataType type =
               
SqlTypeUtil.leastRestrictiveForComparison(operatorBinding.getTypeFactory(),
-                  types[i], types[i - 1]);
+                  types[i], types[prev]);
           if (type == null) {
             if (!throwOnFailure) {
               return false;
@@ -1276,6 +1281,7 @@ public abstract class OperandTypes {
                 RESOURCE.needSameTypeParameter());
           }
         }
+        prev = i;
       }
       return true;
     }

Reply via email to