NobiGo commented on code in PR #4362:
URL: https://github.com/apache/calcite/pull/4362#discussion_r2144621261


##########
core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java:
##########
@@ -563,6 +564,78 @@ protected boolean booleanEquality(SqlCallBinding binding,
     return false;
   }
 
+  /**
+   * {@inheritDoc}
+   *
+   * <p>STRATEGIES
+   *
+   * <p>To determine the common type:
+   *
+   * <ul>
+   *
+   * <li>When the LHS has a Simple type and RHS has a Collection type 
determined by {@link SqlTypeUtil#isCollection},
+   * to find the common type of LHS's type and RHS's component type.
+   * <li>If the common type differs from the LHS type, then coerced LHS type,
+   * and nullable remains unchanged.
+   * <li>Create a new Collection type that matches the common type,
+   * and nullable keep same as RHS's component type and RHS's collection type.
+   * <li>If this new Collection type differs from the RHS type, adjust the RHS 
type as needed.
+   *
+   *<pre>
+   * field1       ARRAY(field2, field3, field4)
+   *    |                |       |       |
+   *    |                +-------+-------+
+   *    |                        |
+   *    |                  component type
+   *    |                        |
+   *    +------common type-------+
+   *</pre>
+   *
+   * <li>Notice: If either LHS or RHS has a {@link SqlTypeName#NULL} type, it 
will directly return without any adjusting.
+   * </ul>
+   */
+  @Override public boolean quantifyOperationCoercion(SqlCallBinding binding) {
+    final RelDataType type1 = binding.getOperandType(0);
+    final RelDataType collectionType = binding.getOperandType(1);
+    final RelDataType type2 = collectionType.getComponentType();
+    assert type2 != null;
+    if (type1.getSqlTypeName() == SqlTypeName.NULL || type2.getSqlTypeName() 
== SqlTypeName.NULL) {
+      return false;
+    }
+    final SqlCall sqlCall = binding.getCall();
+    final SqlValidatorScope scope = binding.getScope();
+    final SqlNode node1 = binding.operand(0);
+    final SqlNode node2 = binding.operand(1);
+    RelDataType widenType = commonTypeForBinaryComparison(type1, type2);
+    if (widenType == null) {
+      widenType = getTightestCommonType(type1, type2);
+    }
+    if (widenType == null) {
+      return false;

Review Comment:
   `False` means will throw compatible types exception.



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