caicancai commented on code in PR #3847:
URL: https://github.com/apache/calcite/pull/3847#discussion_r1676829780


##########
core/src/main/java/org/apache/calcite/sql/type/OperandTypes.java:
##########
@@ -1491,6 +1496,43 @@ private static class PeriodOperandTypeChecker
     }
   }
 
+  /**
+   * Parameter type-checking strategy where types must be Map
+   * and adjust their types to suit the Map function's constructor.
+   */
+  private static class MapSparkFunctionOperandTypeChecker extends 
SameOperandTypeChecker {
+    MapSparkFunctionOperandTypeChecker() {
+      super(1);
+    }
+
+    @Override public boolean checkOperandTypes(
+        SqlCallBinding callBinding,
+        boolean throwOnFailure) {
+
+      final SqlNode op0 = callBinding.operand(0);
+      if (!OperandTypes.MAP.checkSingleOperandType(
+          callBinding,
+          op0,
+          0,
+          throwOnFailure)) {
+        return false;
+      }
+
+      final RelDataType mapKeyType =
+          getKeyTypeOrThrow(SqlTypeUtil.deriveType(callBinding, op0));
+      final RelDataType mapValueType =
+          getValueTypeOrThrow(SqlTypeUtil.deriveType(callBinding, op0));
+
+      // If the key and value types are not unknown,
+      // adjust their types to suit the Map function's constructor.
+      if (mapKeyType.getSqlTypeName() != SqlTypeName.UNKNOWN

Review Comment:
   Currently, this type check is specially prepared for Spark's map function, 
but there may be some problems that are difficult to eliminate as you said. 
However, Spark currently performs some type conversions during parameter 
checking. I have to admit that Spark does not do this very well. 
    
   I believe that after I have a deeper understanding of Calcite and the type 
system in the future, I can improve this part. I hope that day will not be too 
far away.



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