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


##########
core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java:
##########
@@ -1555,9 +1557,34 @@ private static class MapFunctionOperandTypeChecker
         }
         return false;
       }
+      // Insert implicit casts for operands whose SqlTypeName differs
+      // from the inferred key/value type.
+      coerceOperands(callBinding, argTypes,
+          componentType.left, componentType.right);
       return true;
     }
 
+    /** Casts operands whose {@code SqlTypeName} differs from the
+     * target key or value type. Operands at even positions are keys,
+     * odd positions are values. */
+    private static void coerceOperands(SqlCallBinding callBinding,
+        List<RelDataType> operandTypes,
+        RelDataType keyType, RelDataType valueType) {
+      final SqlCall call = callBinding.getCall();
+      final List<SqlNode> operands = call.getOperandList();
+      for (int i = 0; i < operands.size(); i++) {
+        final RelDataType targetType = i % 2 == 0 ? keyType : valueType;
+        if (operandTypes.get(i).getSqlTypeName()
+            != targetType.getSqlTypeName()) {
+          call.setOperand(i,
+              SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO,

Review Comment:
   The newly created cast node will not have a type in the typemap. You have to 
insert it there as well.



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