liuyongvs commented on code in PR #15797:
URL: https://github.com/apache/flink/pull/15797#discussion_r1127263610


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CollectionFunctionsITCase.java:
##########
@@ -160,6 +166,117 @@ Stream<TestSetSpec> getTestSetSpecs() {
                                     null
                                 },
                                 DataTypes.ARRAY(
-                                        DataTypes.ROW(DataTypes.BOOLEAN(), 
DataTypes.DATE()))));
+                                        DataTypes.ROW(DataTypes.BOOLEAN(), 
DataTypes.DATE()))),
+                TestSetSpec.forFunction(BuiltInFunctionDefinitions.MAP_KEYS)
+                        .onFieldsWithData(
+                                null,
+                                "item",
+                                Collections.singletonMap(1, "value"),
+                                Collections.singletonMap(new Integer[] {1, 2}, 
"value"))
+                        .andDataTypes(
+                                DataTypes.BOOLEAN().nullable(),
+                                DataTypes.STRING(),
+                                DataTypes.MAP(DataTypes.INT(), 
DataTypes.STRING()),
+                                
DataTypes.MAP(DataTypes.ARRAY(DataTypes.INT()), DataTypes.STRING()))
+                        .testTableApiValidationError(
+                                call("MAP_KEYS", $("f0"), $("f1")),
+                                "Invalid function call:\nMAP_KEYS(BOOLEAN, 
STRING)")
+                        .testResult(
+                                map(
+                                                
$("f0").cast(DataTypes.BOOLEAN()),
+                                                
$("f1").cast(DataTypes.STRING()))
+                                        .mapKeys(),
+                                "MAP_KEYS(MAP[CAST(f0 AS BOOLEAN), CAST(f1 AS 
STRING)])",
+                                new Boolean[] {null},
+                                DataTypes.ARRAY(DataTypes.BOOLEAN()).notNull())
+                        .testResult(
+                                $("f2").mapKeys(),
+                                "MAP_KEYS(f2)",
+                                new Integer[] {1},
+                                DataTypes.ARRAY(DataTypes.INT()))
+                        .testResult(
+                                $("f3").mapKeys(),
+                                "MAP_KEYS(f3)",
+                                new Integer[][] {new Integer[] {1, 2}},
+                                
DataTypes.ARRAY(DataTypes.ARRAY(DataTypes.INT()))),
+                TestSetSpec.forFunction(BuiltInFunctionDefinitions.MAP_VALUES)
+                        .onFieldsWithData(
+                                null,
+                                "item",
+                                Collections.singletonMap(1, "value1"),
+                                Collections.singletonMap(
+                                        3, Collections.singletonMap(true, 
"value2")))
+                        .andDataTypes(
+                                DataTypes.BOOLEAN().nullable(),
+                                DataTypes.STRING(),
+                                DataTypes.MAP(DataTypes.INT(), 
DataTypes.STRING()),
+                                DataTypes.MAP(
+                                        DataTypes.INT(),
+                                        DataTypes.MAP(DataTypes.BOOLEAN(), 
DataTypes.STRING())))
+                        .testTableApiValidationError(
+                                call("MAP_VALUES", $("f0"), $("f1")),
+                                "Invalid function call:\nMAP_VALUES(BOOLEAN, 
STRING)")
+                        .testResult(
+                                map(
+                                                
$("f1").cast(DataTypes.STRING()),
+                                                
$("f0").cast(DataTypes.BOOLEAN()))
+                                        .mapValues(),
+                                "MAP_VALUES(MAP[CAST(f1 AS STRING), CAST(f0 AS 
BOOLEAN)])",
+                                new Boolean[] {null},
+                                DataTypes.ARRAY(DataTypes.BOOLEAN()).notNull())
+                        .testResult(
+                                $("f2").mapValues(),
+                                "MAP_VALUES(f2)",
+                                new String[] {"value1"},
+                                DataTypes.ARRAY(DataTypes.STRING()))
+                        .testResult(
+                                $("f3").mapValues(),
+                                "MAP_VALUES(f3)",
+                                new Map[] {Collections.singletonMap(true, 
"value2")},
+                                DataTypes.ARRAY(
+                                        DataTypes.MAP(DataTypes.BOOLEAN(), 
DataTypes.STRING()))),
+                
TestSetSpec.forFunction(BuiltInFunctionDefinitions.MAP_FROM_ARRAYS, "Invalid 
input")
+                        .onFieldsWithData(null, null, new Integer[] {1}, new 
Integer[] {1, 2})
+                        .andDataTypes(
+                                DataTypes.BOOLEAN().nullable(),
+                                DataTypes.INT().nullable(),
+                                DataTypes.ARRAY(DataTypes.INT()),
+                                DataTypes.ARRAY(DataTypes.INT()))
+                        .testTableApiRuntimeError(
+                                mapFromArrays($("f2"), $("f3")),
+                                "Invalid function MAP_FROM_ARRAYS call:\n"
+                                        + "The length of the keys array 1 is 
not equal to the length of the values array 2")
+                        .testSqlRuntimeError(
+                                "MAP_FROM_ARRAYS(array[1, 2, 3], array[1, 2])",
+                                "Invalid function MAP_FROM_ARRAYS call:\n"
+                                        + "The length of the keys array 3 is 
not equal to the length of the values array 2"),
+                
TestSetSpec.forFunction(BuiltInFunctionDefinitions.MAP_FROM_ARRAYS)
+                        .onFieldsWithData(
+                                new Integer[] {1, 2},
+                                new String[] {"one", "two"},
+                                new Integer[][] {new Integer[] {1, 2}, new 
Integer[] {3, 4}})
+                        .andDataTypes(
+                                DataTypes.ARRAY(DataTypes.INT()),
+                                DataTypes.ARRAY(DataTypes.STRING()),
+                                
DataTypes.ARRAY(DataTypes.ARRAY(DataTypes.INT())))
+                        .testResult(
+                                mapFromArrays($("f0"), $("f1")),
+                                "MAP_FROM_ARRAYS(f0, f1)",
+                                of(1, "one", 2, "two"),
+                                DataTypes.MAP(DataTypes.INT(), 
DataTypes.STRING()))
+                        .testTableApiResult(
+                                mapFromArrays($("f1"), $("f2")),
+                                of("one", new Integer[] {1, 2}, "two", new 
Integer[] {3, 4}),
+                                DataTypes.MAP(
+                                        DataTypes.STRING(), 
DataTypes.ARRAY(DataTypes.INT()))));
+    }
+
+    // 
--------------------------------------------------------------------------------------------
+
+    private static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2) {
+        Map<K, V> map = new HashMap<>();
+        map.put(k1, v1);
+        map.put(k2, v2);

Review Comment:
   yeap, i just comments there are examples in MapFunctionITCase. 



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