You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "luoyuxia (via GitHub)" <gi...@apache.org> on 2023/06/07 07:46:36 UTC

[GitHub] [flink] luoyuxia commented on a diff in pull request #22312: [FLINK-31677][table] Add built-in MAP_ENTRIES function.

luoyuxia commented on code in PR #22312:
URL: https://github.com/apache/flink/pull/22312#discussion_r1221074956


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/SpecificTypeStrategies.java:
##########
@@ -89,6 +95,49 @@ public final class SpecificTypeStrategies {
     /** See {@link ToTimestampLtzTypeStrategy}. */
     public static final TypeStrategy TO_TIMESTAMP_LTZ = new ToTimestampLtzTypeStrategy();
 
+    /** Type strategy specific for {@link BuiltInFunctionDefinitions#MAP_KEYS}. */
+    public static final TypeStrategy MAP_KEYS =
+            callContext ->
+                    Optional.of(
+                            DataTypes.ARRAY(
+                                    ((KeyValueDataType) callContext.getArgumentDataTypes().get(0))
+                                            .getKeyDataType()));
+
+    /** Type strategy specific for {@link BuiltInFunctionDefinitions#MAP_VALUES}. */
+    public static final TypeStrategy MAP_VALUES =
+            callContext ->
+                    Optional.of(
+                            DataTypes.ARRAY(
+                                    ((KeyValueDataType) callContext.getArgumentDataTypes().get(0))
+                                            .getValueDataType()));
+
+    /** Type strategy specific for {@link BuiltInFunctionDefinitions#MAP_ENTRIES}. */
+    public static final TypeStrategy MAP_ENTRIES =
+            callContext ->
+                    Optional.of(
+                            DataTypes.ARRAY(
+                                    DataTypes.ROW(

Review Comment:
   Do we need to specify the name for  each field of the `Row` type? Btw, seems spark use
   ```
         StructType(
           StructField("key", childDataType.keyType, false) ::
           StructField("value", childDataType.valueType, childDataType.valueContainsNull) ::
           Nil)
   ````



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org