xuyangzhong commented on code in PR #24106:
URL: https://github.com/apache/flink/pull/24106#discussion_r1462969824


##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/extraction/TypeInferenceExtractorTest.java:
##########
@@ -535,7 +535,43 @@ private static Stream<TestSpec> functionSpecs() {
                                         new String[] {}, new 
ArgumentTypeStrategy[] {}),
                                 TypeStrategies.explicit(
                                         DataTypes.ROW(DataTypes.FIELD("i", 
DataTypes.INT()))
-                                                .bridgedTo(RowData.class))));
+                                                .bridgedTo(RowData.class))),
+                TestSpec.forScalarFunction(
+                                "Scalar function with arguments hints",
+                                ArgumentHintScalarFunction.class)
+                        .expectNamedArguments("f1", "f2")
+                        .expectTypedArguments(DataTypes.STRING(), 
DataTypes.INT())
+                        .expectOutputMapping(
+                                InputTypeStrategies.sequence(
+                                        new String[] {"f1", "f2"},
+                                        new ArgumentTypeStrategy[] {
+                                            
InputTypeStrategies.explicit(DataTypes.STRING()),
+                                            
InputTypeStrategies.explicit(DataTypes.INT())
+                                        }),
+                                TypeStrategies.explicit(DataTypes.STRING())),
+                TestSpec.forScalarFunction(
+                                "Scalar function with arguments hints and 
inputs hints both defined",
+                                ArgumentsAndInputsScalarFunction.class)
+                        .expectErrorMessage(
+                                "Unable to support specifying both inputs and 
arguments at the same time"),
+                TestSpec.forScalarFunction(
+                                "Scalar function with ArgumentHint and 
DataTypeHint hints both defined",
+                                
ArgumentsHintAndDataTypeHintScalarFunction.class)
+                        .expectErrorMessage(
+                                "ArgumentHint and DataTypeHint cannot be 
declared at the same time."),
+                TestSpec.forScalarFunction(
+                                "Scalar function with FunctionHint on class 
and method",
+                                FunctionHintOnClassAndMethod.class)
+                        .expectErrorMessage(
+                                "Unable to support specifying both inputs and 
arguments at the same time."),
+                TestSpec.forScalarFunction(
+                                "Scalar function with FunctionHint on class 
and method",
+                                MultiFunctionHintOnClass.class)
+                        .expectErrorMessage(
+                                "Considering all hints, the method should 
comply with the signature"),
+                TestSpec.forScalarFunction(

Review Comment:
   ditto



##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/extraction/TypeInferenceExtractorTest.java:
##########
@@ -535,7 +535,43 @@ private static Stream<TestSpec> functionSpecs() {
                                         new String[] {}, new 
ArgumentTypeStrategy[] {}),
                                 TypeStrategies.explicit(
                                         DataTypes.ROW(DataTypes.FIELD("i", 
DataTypes.INT()))
-                                                .bridgedTo(RowData.class))));
+                                                .bridgedTo(RowData.class))),
+                TestSpec.forScalarFunction(
+                                "Scalar function with arguments hints",
+                                ArgumentHintScalarFunction.class)
+                        .expectNamedArguments("f1", "f2")
+                        .expectTypedArguments(DataTypes.STRING(), 
DataTypes.INT())
+                        .expectOutputMapping(
+                                InputTypeStrategies.sequence(
+                                        new String[] {"f1", "f2"},
+                                        new ArgumentTypeStrategy[] {
+                                            
InputTypeStrategies.explicit(DataTypes.STRING()),
+                                            
InputTypeStrategies.explicit(DataTypes.INT())
+                                        }),
+                                TypeStrategies.explicit(DataTypes.STRING())),
+                TestSpec.forScalarFunction(
+                                "Scalar function with arguments hints and 
inputs hints both defined",
+                                ArgumentsAndInputsScalarFunction.class)
+                        .expectErrorMessage(
+                                "Unable to support specifying both inputs and 
arguments at the same time"),
+                TestSpec.forScalarFunction(
+                                "Scalar function with ArgumentHint and 
DataTypeHint hints both defined",
+                                
ArgumentsHintAndDataTypeHintScalarFunction.class)
+                        .expectErrorMessage(
+                                "ArgumentHint and DataTypeHint cannot be 
declared at the same time."),
+                TestSpec.forScalarFunction(
+                                "Scalar function with FunctionHint on class 
and method",
+                                FunctionHintOnClassAndMethod.class)
+                        .expectErrorMessage(
+                                "Unable to support specifying both inputs and 
arguments at the same time."),
+                TestSpec.forScalarFunction(
+                                "Scalar function with FunctionHint on class 
and method",

Review Comment:
   nit: change the desc.



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/runtime/stream/sql/FunctionITCase.java:
##########
@@ -1056,7 +1057,111 @@ void testDynamicCatalogTableFunction() throws Exception 
{
     }
 
     @Test
-    void testInvalidUseOfScalarFunction() {
+    void testNamedArgumentsCatalogTableFunction() throws Exception {

Review Comment:
   nit: remove `Catalog` here



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/runtime/stream/sql/FunctionITCase.java:
##########
@@ -1056,7 +1057,111 @@ void testDynamicCatalogTableFunction() throws Exception 
{
     }
 
     @Test
-    void testInvalidUseOfScalarFunction() {
+    void testNamedArgumentsCatalogTableFunction() throws Exception {
+        final Row[] sinkData = new Row[] {Row.of("str1, str2")};
+
+        TestCollectionTableFactory.reset();
+
+        tEnv().executeSql("CREATE TABLE SinkTable(s STRING) WITH ('connector' 
= 'COLLECTION')");
+
+        tEnv().createFunction("NamedArgumentsTableFunction", 
NamedArgumentsTableFunction.class);
+        tEnv().executeSql(
+                        "INSERT INTO SinkTable "
+                                + "SELECT T1.s FROM 
TABLE(NamedArgumentsTableFunction(in2 => 'str2', in1 => 'str1')) AS T1(s) ")
+                .await();
+
+        
assertThat(TestCollectionTableFactory.getResult()).containsExactlyInAnyOrder(sinkData);
+    }
+
+    @Test
+    void testNamedArgumentsScalarFunction() throws Exception {
+        final List<Row> sourceData =
+                Arrays.asList(Row.of(1, 2, "str1"), Row.of(3, 4, "str2"), 
Row.of(5, 6, "str3"));
+
+        final List<Row> sinkData =
+                Arrays.asList(Row.of(0, 0, "1: 2"), Row.of(0, 0, "3: 4"), 
Row.of(0, 0, "5: 6"));
+
+        TestCollectionTableFactory.reset();
+        TestCollectionTableFactory.initData(sourceData);
+
+        tEnv().executeSql(
+                        "CREATE TABLE TestTable(i1 INT NOT NULL, i2 INT NOT 
NULL, s1 STRING) WITH ('connector' = 'COLLECTION')");
+
+        tEnv().createTemporarySystemFunction(
+                        "NamedArgumentsScalarFunction", 
NamedArgumentsScalarFunction.class);
+        tEnv().executeSql(
+                        "INSERT INTO TestTable SELECT"
+                                + " 0 as i1, 0 as i2,"

Review Comment:
   nit: A little curious why i1 and i2 need to be set to 0



##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/extraction/TypeInferenceExtractorTest.java:
##########
@@ -700,7 +736,7 @@ private static Stream<TestSpec> procedureSpecs() {
                                 TypeStrategies.explicit(
                                         
DataTypes.DOUBLE().notNull().bridgedTo(double.class))),
                 // named arguments with overloaded function
-                
TestSpec.forProcedure(NamedArgumentsProcedure.class).expectNamedArguments("n"),
+                TestSpec.forProcedure(NamedArgumentsProcedure.class),

Review Comment:
   ditto



##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/extraction/TypeInferenceExtractorTest.java:
##########
@@ -427,8 +428,7 @@ private static Stream<TestSpec> functionSpecs() {
                                 "Could not find a publicly accessible method 
named 'eval'."),
 
                 // named arguments with overloaded function
-                TestSpec.forScalarFunction(NamedArgumentsScalarFunction.class)
-                        .expectNamedArguments("n"),
+                TestSpec.forScalarFunction(NamedArgumentsScalarFunction.class),

Review Comment:
   What about add `expectxxx` blocks here?



-- 
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-unsubscr...@flink.apache.org

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

Reply via email to