AlanConfluent commented on code in PR #29980:
URL: https://github.com/apache/flink/pull/29980#discussion_r4777971288


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/batch/sql/AsyncCorrelateTest.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.batch.sql;
+
+import org.apache.flink.table.api.TableConfig;
+import org.apache.flink.table.api.TableException;
+import 
org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalAsyncCorrelate;
+import 
org.apache.flink.table.planner.runtime.utils.JavaUserDefinedTableFunctions;
+import org.apache.flink.table.planner.utils.BatchTableTestUtil;
+import org.apache.flink.table.planner.utils.TableTestBase;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Tests for {@link BatchPhysicalAsyncCorrelate}. */
+class AsyncCorrelateTest extends TableTestBase {

Review Comment:
   Same as with the scalar PR.  Seems like you could share a bunch of this with 
AsyncCorrelateSplitRuleTest.



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/batch/sql/AsyncCorrelateTest.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.batch.sql;
+
+import org.apache.flink.table.api.TableConfig;
+import org.apache.flink.table.api.TableException;
+import 
org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalAsyncCorrelate;
+import 
org.apache.flink.table.planner.runtime.utils.JavaUserDefinedTableFunctions;
+import org.apache.flink.table.planner.utils.BatchTableTestUtil;
+import org.apache.flink.table.planner.utils.TableTestBase;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Tests for {@link BatchPhysicalAsyncCorrelate}. */
+class AsyncCorrelateTest extends TableTestBase {
+
+    private BatchTableTestUtil util;
+
+    @BeforeEach
+    void setup() {
+        util = batchTestUtil(TableConfig.getDefault());
+        util.getTableEnv()
+                .executeSql(
+                        "CREATE TABLE MyTable (\n"
+                                + "  a INT NOT NULL,\n"
+                                + "  b BIGINT,\n"
+                                + "  c STRING\n"
+                                + ") WITH (\n"
+                                + "  'connector' = 
'test-simple-table-source'\n"
+                                + ")");
+        util.addTemporarySystemFunction(
+                "asyncTableFunc", new 
JavaUserDefinedTableFunctions.AsyncTestTableFunction());
+        util.addTemporarySystemFunction(
+                "mySum", new 
JavaUserDefinedTableFunctions.SumScalarFunction());
+    }
+
+    @Test
+    void testAsyncCorrelate() {
+        util.verifyExecPlan("SELECT * FROM MyTable, LATERAL 
asyncTableFunc(a)");
+    }
+
+    @Test
+    void testAsyncCorrelateLeftJoin() {
+        util.verifyExecPlan("SELECT * FROM MyTable LEFT JOIN LATERAL 
asyncTableFunc(a) ON TRUE");

Review Comment:
   I don't think this will work at runtime because I don't think the join type 
is passed in to the runner.
   
   Here is my original PR for it but it never got reviewed: 
https://github.com/apache/flink/pull/26817
   
   Might want to stick to operations that are supported for the moment.



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/processor/MultipleInputNodeCreationProcessor.java:
##########
@@ -195,6 +196,10 @@ private boolean 
canBeMultipleInputNodeMember(ExecNodeWrapper wrapper) {
             // exchange cannot be a member of multiple input node
             return false;
         }
+        if (wrapper.execNode instanceof BatchExecAsyncCorrelate) {

Review Comment:
   Same comment: There are some other AsyncWaitOperatorFactory operators that 
might need to be added here too,



##########
docs/content/docs/dev/table/functions/udfs.md:
##########
@@ -1286,6 +1286,8 @@ Similar to `AsyncScalarFunction`, there also exists a 
`AsyncTableFunction` for r
 
 Asynchronous interaction with an external system means that a single function 
instance can handle many requests concurrently and receive the responses 
concurrently. That way, the waiting time can be overlaid with sending other 
requests and receiving responses. At the very least, the waiting time is 
amortized over multiple requests. This leads in most cases to much higher 
streaming throughput.
 
+`AsyncTableFunction` is supported in both streaming and batch mode.

Review Comment:
   docs/content.zh/docs/dev/table/functions/udfs.md too?



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/batch/BatchExecAsyncCorrelate.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.batch;
+
+import org.apache.flink.FlinkVersion;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.functions.AsyncTableFunction;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNode;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeMetadata;
+import org.apache.flink.table.planner.plan.nodes.exec.InputProperty;
+import 
org.apache.flink.table.planner.plan.nodes.exec.common.CommonExecAsyncCorrelate;
+import org.apache.flink.table.runtime.operators.join.FlinkJoinType;
+import org.apache.flink.table.types.logical.RowType;
+
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexNode;
+
+import java.util.Collections;
+import java.util.List;
+
+/** Batch {@link ExecNode} for {@link AsyncTableFunction}. */
+@ExecNodeMetadata(
+        name = "batch-exec-async-correlate",
+        version = 1,
+        producedTransformations = 
CommonExecAsyncCorrelate.ASYNC_CORRELATE_TRANSFORMATION,
+        minPlanVersion = FlinkVersion.v2_5,
+        minStateVersion = FlinkVersion.v2_5,
+        consumedOptions = {
+            "table.exec.async-table.max-concurrent-operations",

Review Comment:
   Same comment I made on the scalar PR.  I think we might want to leave these 
out of this list.



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/physical/common/CommonPhysicalAsyncCorrelateRule.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.rules.physical.common;
+
+import org.apache.flink.table.functions.AsyncTableFunction;
+import org.apache.flink.table.functions.FunctionKind;
+import org.apache.flink.table.planner.plan.nodes.FlinkConvention;
+import org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc;
+import org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCorrelate;
+import 
org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableFunctionScan;
+import 
org.apache.flink.table.planner.plan.rules.physical.stream.StreamPhysicalCorrelateRule;
+import org.apache.flink.table.planner.plan.utils.AsyncUtil;
+
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.plan.volcano.RelSubset;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.convert.ConverterRule;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexNode;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * Base rule for converting logical correlates containing {@link 
AsyncTableFunction} calls to a
+ * physical async correlate. Subclasses only create the physical node of their 
convention.
+ */
+public abstract class CommonPhysicalAsyncCorrelateRule extends ConverterRule {
+
+    protected CommonPhysicalAsyncCorrelateRule(Config config) {
+        super(config);
+    }
+
+    // find only calc and table function
+    private boolean findAsyncTableFunction(RelNode node) {
+        if (node instanceof FlinkLogicalTableFunctionScan) {
+            FlinkLogicalTableFunctionScan scan = 
(FlinkLogicalTableFunctionScan) node;
+            return AsyncUtil.isAsyncCall(scan.getCall(), 
FunctionKind.ASYNC_TABLE);
+        } else if (node instanceof FlinkLogicalCalc) {
+            FlinkLogicalCalc calc = (FlinkLogicalCalc) node;
+            RelNode child = ((RelSubset) calc.getInput()).getOriginal();
+            return findAsyncTableFunction(child);
+        }
+        return false;
+    }
+
+    @Override
+    public boolean matches(RelOptRuleCall call) {
+        FlinkLogicalCorrelate correlate = call.rel(0);
+        RelNode right = ((RelSubset) correlate.getRight()).getOriginal();
+        return findAsyncTableFunction(right);
+    }
+
+    @Override
+    public RelNode convert(RelNode rel) {
+        FlinkLogicalCorrelate correlate = (FlinkLogicalCorrelate) rel;
+        FlinkConvention convention = (FlinkConvention) getOutConvention();
+        RelTraitSet traitSet = rel.getTraitSet().replace(convention);
+        RelNode convInput = RelOptRule.convert(correlate.getInput(0), 
convention);
+        RelNode right = correlate.getInput(1);
+        return convertToCorrelate(
+                right, correlate, traitSet, convInput, Optional.empty(), 
Optional.empty());
+    }
+
+    private RelNode convertToCorrelate(
+            RelNode relNode,
+            FlinkLogicalCorrelate correlate,
+            RelTraitSet traitSet,
+            RelNode convInput,
+            Optional<List<RexNode>> projections,
+            Optional<RexNode> condition) {
+        if (relNode instanceof RelSubset) {
+            RelSubset rel = (RelSubset) relNode;
+            return convertToCorrelate(
+                    rel.getRelList().get(0),
+                    correlate,
+                    traitSet,
+                    convInput,
+                    projections,
+                    condition);
+        } else if (relNode instanceof FlinkLogicalCalc) {
+            FlinkLogicalCalc calc = (FlinkLogicalCalc) relNode;
+            RelNode tableScan = StreamPhysicalCorrelateRule.getTableScan(calc);

Review Comment:
   It's a little funny to call into streaming classes from the common one.  Can 
you just move those methods to this class?



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