twalthr commented on code in PR #24220:
URL: https://github.com/apache/flink/pull/24220#discussion_r1470990008


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/AsyncCalcTestPrograms.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.planner.plan.nodes.exec.stream;
+
+import 
org.apache.flink.table.planner.runtime.utils.JavaUserDefinedScalarFunctions;
+import org.apache.flink.table.test.program.SinkTestStep;
+import org.apache.flink.table.test.program.SourceTestStep;
+import org.apache.flink.table.test.program.TableTestProgram;
+import org.apache.flink.types.Row;
+
+import java.time.LocalDateTime;
+
+public class AsyncCalcTestPrograms {
+
+    static final TableTestProgram ASYNC_CALC_UDF_SIMPLE =
+            TableTestProgram.of("async-calc-simple", "validates async calc 
node with simple UDF")
+                    .setupTemporaryCatalogFunction(
+                            "udf1", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc0.class)
+                    .setupTableSource(
+                            SourceTestStep.newBuilder("source_t")
+                                    .addSchema("a INT")
+                                    .producedBeforeRestore(Row.of(5))
+                                    .producedAfterRestore(Row.of(5))
+                                    .build())
+                    .setupTableSink(
+                            SinkTestStep.newBuilder("sink_t")
+                                    .addSchema("a INT", "a1 BIGINT")
+                                    .consumedBeforeRestore(Row.of(5, 6L))
+                                    .consumedAfterRestore(Row.of(5, 6L))
+                                    .build())
+                    .runSql("INSERT INTO sink_t SELECT a, udf1(a) FROM 
source_t")
+                    .build();
+
+    static final TableTestProgram ASYNC_CALC_UDF_COMPLEX =
+            TableTestProgram.of("async-calc-complex", "validates calc node 
with complex UDFs")
+                    .setupTemporaryCatalogFunction(
+                            "udf1", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc0.class)
+                    .setupTemporaryCatalogFunction(
+                            "udf2", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc1.class)
+                    .setupTemporarySystemFunction(
+                            "udf3", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc2.class)
+                    .setupTemporarySystemFunction(
+                            "udf4", 
JavaUserDefinedScalarFunctions.AsyncUdfWithOpen.class)
+                    .setupCatalogFunction(
+                            "udf5", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc5.class)
+                    .setupTableSource(
+                            SourceTestStep.newBuilder("source_t")
+                                    .addSchema(
+                                            "a BIGINT, b INT NOT NULL, c 
VARCHAR, d TIMESTAMP(3)")
+                                    .producedBeforeRestore(
+                                            Row.of(
+                                                    5L,
+                                                    11,
+                                                    "hello world",
+                                                    LocalDateTime.of(2023, 12, 
16, 1, 1, 1, 123)))
+                                    .producedAfterRestore(
+                                            Row.of(
+                                                    5L,
+                                                    11,
+                                                    "hello world",
+                                                    LocalDateTime.of(2023, 12, 
16, 1, 1, 1, 123)))
+                                    .build())
+                    .setupTableSink(
+                            SinkTestStep.newBuilder("sink_t")
+                                    .addSchema(
+                                            "a BIGINT",
+                                            "a1 VARCHAR",
+                                            "b INT NOT NULL",
+                                            "b1 VARCHAR",
+                                            "c1 VARCHAR",
+                                            "c2 VARCHAR",
+                                            "d1 TIMESTAMP(3)")
+                                    .consumedBeforeRestore(
+                                            Row.of(
+                                                    5L,
+                                                    "5",
+                                                    11,
+                                                    "11 and 11 and 
1702688461000",
+                                                    "hello world11",
+                                                    "$hello",
+                                                    LocalDateTime.of(2023, 12, 
16, 01, 01, 00, 0)))
+                                    .consumedAfterRestore(
+                                            Row.of(
+                                                    5L,
+                                                    "5",
+                                                    11,
+                                                    "11 and 11 and 
1702688461000",
+                                                    "hello world11",
+                                                    "$hello",
+                                                    LocalDateTime.of(2023, 12, 
16, 01, 01, 00, 0)))
+                                    .build())
+                    .runSql(
+                            "INSERT INTO sink_t SELECT "
+                                    + "a, "
+                                    + "cast(a as VARCHAR) as a1, "
+                                    + "b, "
+                                    + "udf2(b, b, d) as b1, "
+                                    + "udf3(c, b) as c1, "
+                                    + "udf4(substring(c, 1, 5)) as c2, "
+                                    + "udf5(d, 1000) as d1 "
+                                    + "from source_t where "
+                                    + "(udf1(a) > 0 or (a * b) < 100) and b > 
10")
+                    .build();
+
+    static final TableTestProgram ASYNC_CALC_UDF_NESTED =
+            TableTestProgram.of("async-calc-nested", "validates async calc 
node with simple UDF")

Review Comment:
   update explanation



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/AsyncCalcTestPrograms.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.planner.plan.nodes.exec.stream;
+
+import 
org.apache.flink.table.planner.runtime.utils.JavaUserDefinedScalarFunctions;
+import org.apache.flink.table.test.program.SinkTestStep;
+import org.apache.flink.table.test.program.SourceTestStep;
+import org.apache.flink.table.test.program.TableTestProgram;
+import org.apache.flink.types.Row;
+
+import java.time.LocalDateTime;
+
+public class AsyncCalcTestPrograms {
+
+    static final TableTestProgram ASYNC_CALC_UDF_SIMPLE =
+            TableTestProgram.of("async-calc-simple", "validates async calc 
node with simple UDF")
+                    .setupTemporaryCatalogFunction(
+                            "udf1", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc0.class)
+                    .setupTableSource(
+                            SourceTestStep.newBuilder("source_t")
+                                    .addSchema("a INT")
+                                    .producedBeforeRestore(Row.of(5))
+                                    .producedAfterRestore(Row.of(5))
+                                    .build())
+                    .setupTableSink(
+                            SinkTestStep.newBuilder("sink_t")
+                                    .addSchema("a INT", "a1 BIGINT")
+                                    .consumedBeforeRestore(Row.of(5, 6L))
+                                    .consumedAfterRestore(Row.of(5, 6L))
+                                    .build())
+                    .runSql("INSERT INTO sink_t SELECT a, udf1(a) FROM 
source_t")
+                    .build();
+
+    static final TableTestProgram ASYNC_CALC_UDF_COMPLEX =
+            TableTestProgram.of("async-calc-complex", "validates calc node 
with complex UDFs")
+                    .setupTemporaryCatalogFunction(
+                            "udf1", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc0.class)
+                    .setupTemporaryCatalogFunction(
+                            "udf2", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc1.class)
+                    .setupTemporarySystemFunction(
+                            "udf3", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc2.class)
+                    .setupTemporarySystemFunction(
+                            "udf4", 
JavaUserDefinedScalarFunctions.AsyncUdfWithOpen.class)
+                    .setupCatalogFunction(
+                            "udf5", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc5.class)
+                    .setupTableSource(
+                            SourceTestStep.newBuilder("source_t")
+                                    .addSchema(
+                                            "a BIGINT, b INT NOT NULL, c 
VARCHAR, d TIMESTAMP(3)")
+                                    .producedBeforeRestore(
+                                            Row.of(
+                                                    5L,
+                                                    11,
+                                                    "hello world",
+                                                    LocalDateTime.of(2023, 12, 
16, 1, 1, 1, 123)))
+                                    .producedAfterRestore(
+                                            Row.of(
+                                                    5L,
+                                                    11,
+                                                    "hello world",
+                                                    LocalDateTime.of(2023, 12, 
16, 1, 1, 1, 123)))
+                                    .build())
+                    .setupTableSink(
+                            SinkTestStep.newBuilder("sink_t")
+                                    .addSchema(
+                                            "a BIGINT",
+                                            "a1 VARCHAR",
+                                            "b INT NOT NULL",
+                                            "b1 VARCHAR",
+                                            "c1 VARCHAR",
+                                            "c2 VARCHAR",
+                                            "d1 TIMESTAMP(3)")
+                                    .consumedBeforeRestore(
+                                            Row.of(
+                                                    5L,
+                                                    "5",
+                                                    11,
+                                                    "11 and 11 and 
1702688461000",
+                                                    "hello world11",
+                                                    "$hello",
+                                                    LocalDateTime.of(2023, 12, 
16, 01, 01, 00, 0)))
+                                    .consumedAfterRestore(
+                                            Row.of(
+                                                    5L,
+                                                    "5",
+                                                    11,
+                                                    "11 and 11 and 
1702688461000",
+                                                    "hello world11",
+                                                    "$hello",
+                                                    LocalDateTime.of(2023, 12, 
16, 01, 01, 00, 0)))
+                                    .build())
+                    .runSql(
+                            "INSERT INTO sink_t SELECT "
+                                    + "a, "
+                                    + "cast(a as VARCHAR) as a1, "
+                                    + "b, "
+                                    + "udf2(b, b, d) as b1, "
+                                    + "udf3(c, b) as c1, "
+                                    + "udf4(substring(c, 1, 5)) as c2, "
+                                    + "udf5(d, 1000) as d1 "
+                                    + "from source_t where "
+                                    + "(udf1(a) > 0 or (a * b) < 100) and b > 
10")
+                    .build();
+
+    static final TableTestProgram ASYNC_CALC_UDF_NESTED =
+            TableTestProgram.of("async-calc-nested", "validates async calc 
node with simple UDF")
+                    .setupTemporaryCatalogFunction(
+                            "udf1", 
JavaUserDefinedScalarFunctions.AsyncJavaFunc0.class)
+                    .setupTableSource(
+                            SourceTestStep.newBuilder("source_t")
+                                    .addSchema("a INT")
+                                    .producedBeforeRestore(Row.of(5))
+                                    .producedAfterRestore(Row.of(5))
+                                    .build())
+                    .setupTableSink(
+                            SinkTestStep.newBuilder("sink_t")
+                                    .addSchema("a INT", "a1 BIGINT")
+                                    .consumedBeforeRestore(Row.of(5, 8L))
+                                    .consumedAfterRestore(Row.of(5, 8L))
+                                    .build())
+                    .runSql("INSERT INTO sink_t SELECT a, udf1(udf1(udf1(a))) 
FROM source_t")
+                    .build();
+
+    static final TableTestProgram ASYNC_CALC_UDF_CONDITION =
+            TableTestProgram.of("async-calc-condition", "validates async calc 
node with simple UDF")

Review Comment:
   update explanation



##########
flink-table/flink-table-planner/src/test/resources/restore-tests/stream-exec-calc_1/async-calc-condition/plan/async-calc-condition.json:
##########
@@ -0,0 +1,186 @@
+{
+  "flinkVersion" : "1.19",
+  "nodes" : [ {
+    "id" : 20,
+    "type" : "stream-exec-table-source-scan_1",
+    "scanTableSource" : {
+      "table" : {
+        "identifier" : "`default_catalog`.`default_database`.`source_t`",
+        "resolvedTable" : {
+          "schema" : {
+            "columns" : [ {
+              "name" : "a",
+              "dataType" : "INT"
+            } ],
+            "watermarkSpecs" : [ ]
+          },
+          "partitionKeys" : [ ]
+        }
+      },
+      "abilities" : [ {
+        "type" : "FilterPushDown",
+        "predicates" : [ ]
+      } ]
+    },
+    "outputType" : "ROW<`a` INT>",
+    "description" : "TableSourceScan(table=[[default_catalog, 
default_database, source_t, filter=[]]], fields=[a])",
+    "inputProperties" : [ ]
+  }, {
+    "id" : 21,
+    "type" : "stream-exec-calc_1",
+    "projection" : [ {
+      "kind" : "INPUT_REF",
+      "inputIndex" : 0,
+      "type" : "INT"
+    }, {
+      "kind" : "CALL",
+      "syntax" : "SPECIAL",
+      "internalName" : "$CAST$1",
+      "operands" : [ {
+        "kind" : "INPUT_REF",
+        "inputIndex" : 0,
+        "type" : "INT"
+      } ],
+      "type" : "BIGINT"
+    } ],
+    "condition" : null,
+    "inputProperties" : [ {
+      "requiredDistribution" : {
+        "type" : "UNKNOWN"
+      },
+      "damBehavior" : "PIPELINED",
+      "priority" : 0
+    } ],
+    "outputType" : "ROW<`a` INT, `f0` BIGINT>",
+    "description" : "Calc(select=[a, CAST(a AS BIGINT) AS f0])"
+  }, {
+    "id" : 22,
+    "type" : "stream-exec-async-calc_1",
+    "configuration" : {
+      "table.exec.async-scalar.buffer-capacity" : "10",

Review Comment:
   It would be nice to have at least one test that actually tests the 
parameters. Not sure how feasible this is but would it be possible to come up 
with a function that fails for 2 attempts and the the 3rd attempt actually 
happens after restore (by matching against a certain input arg for example?).



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/runtime/utils/JavaUserDefinedScalarFunctions.java:
##########
@@ -318,4 +320,91 @@ public PythonEnv getPythonEnv() {
             return null;
         }
     }
+
+    /** Increment input. */
+    public static class AsyncJavaFunc0 extends AsyncScalarFunction {

Review Comment:
   move those functions into `AsyncCalcTestPrograms` to have complete test 
programs. functions should not be shared across tests.



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