matriv commented on code in PR #19648:
URL: https://github.com/apache/flink/pull/19648#discussion_r866767984


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/utils/SqlValidatorUtils.java:
##########
@@ -76,9 +80,27 @@ private static void adjustTypeForMultisetConstructor(
     }
 
     private static SqlNode castTo(SqlNode node, RelDataType type) {
-        return SqlStdOperatorTable.CAST.createCall(
-                SqlParserPos.ZERO,
-                node,
-                
SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable()));
+        SqlDataTypeSpec dataTypeSpec;

Review Comment:
   ```suggestion
           final SqlDataTypeSpec dataTypeSpec;
   ```



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/batch/sql/CalcTest.scala:
##########
@@ -187,4 +187,13 @@ class CalcTest extends TableTestBase {
   def testDecimalMapWithDifferentPrecision(): Unit = {
     util.verifyExecPlan("SELECT MAP['a', 0.12, 'b', 0.5]")
   }
+
+  @Test
+  def testCastMapValueInsideArray(): Unit = {
+    util.verifyExecPlan(

Review Comment:
   Can we also add a test where the key or value (or both) is of some other 
type, like a numeric?



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/stream/sql/CalcTest.scala:
##########
@@ -181,4 +181,13 @@ class CalcTest extends TableTestBase {
   def testDecimalMapWithDifferentPrecision(): Unit = {
     util.verifyExecPlan("SELECT MAP['a', 0.12, 'b', 0.5]")
   }
+
+  @Test
+  def testCastMapValueInsideArray(): Unit = {
+    util.verifyExecPlan(

Review Comment:
   same here



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/utils/SqlValidatorUtils.java:
##########
@@ -76,9 +80,27 @@ private static void adjustTypeForMultisetConstructor(
     }
 
     private static SqlNode castTo(SqlNode node, RelDataType type) {
-        return SqlStdOperatorTable.CAST.createCall(
-                SqlParserPos.ZERO,
-                node,
-                
SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable()));
+        SqlDataTypeSpec dataTypeSpec;
+        if (SqlTypeUtil.isMap(type)) {
+            dataTypeSpec = getMapSqlDataTypeSpec(type);
+        } else {
+            dataTypeSpec = 
SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable());
+        }
+
+        return SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, node, 
dataTypeSpec);
+    }
+
+    private static SqlDataTypeSpec getMapSqlDataTypeSpec(RelDataType type) {
+        SqlDataTypeSpec dataTypeSpec;

Review Comment:
   ```suggestion
           final RelDataType keyType = type.getKeyType();
           final RelDataType valueType = type.getValueType();
           final SqlTypeNameSpec sqlTypeNameSpec =
                   new SqlMapTypeNameSpec(
                           
SqlTypeUtil.convertTypeToSpec(keyType).withNullable(keyType.isNullable()),
                           SqlTypeUtil.convertTypeToSpec(valueType)
                                   .withNullable(valueType.isNullable()),
                           SqlParserPos.ZERO);
           return new SqlDataTypeSpec(sqlTypeNameSpec, SqlParserPos.ZERO);
   ```



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