hequn8128 commented on a change in pull request #11051: 
[FLINK-15961][table-planner][table-planner-blink] Introduce Python Physical 
Correlate RelNodes which are containers for Python TableFunction
URL: https://github.com/apache/flink/pull/11051#discussion_r379244079
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/rules/physical/stream/StreamExecPythonCorrelateRule.java
 ##########
 @@ -0,0 +1,136 @@
+/*
+ * 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.stream;
+
+import org.apache.flink.table.planner.plan.nodes.FlinkConventions;
+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.nodes.physical.stream.StreamExecPythonCorrelate;
+import org.apache.flink.table.planner.plan.utils.PythonUtil;
+
+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.rex.RexNode;
+
+import scala.Option;
+import scala.Some;
+
+/**
+ * The physical rule is responsible for convert {@link FlinkLogicalCorrelate} 
to
+ * {@link StreamExecPythonCorrelate}.
+ */
+public class StreamExecPythonCorrelateRule extends ConverterRule {
+
+       public static final RelOptRule INSTANCE = new 
StreamExecPythonCorrelateRule();
+
+       private StreamExecPythonCorrelateRule() {
+               super(FlinkLogicalCorrelate.class, FlinkConventions.LOGICAL(), 
FlinkConventions.STREAM_PHYSICAL(),
+                       "StreamExecPythonCorrelateRule");
+       }
+
+       // find only calc and table function
+       private boolean findTableFunction(FlinkLogicalCalc calc) {
+               RelNode child = ((RelSubset) calc.getInput()).getOriginal();
+               if (child instanceof FlinkLogicalTableFunctionScan) {
+                       FlinkLogicalTableFunctionScan scan = 
(FlinkLogicalTableFunctionScan) child;
+                       return PythonUtil.isPythonCall(scan.getCall());
+               } else if (child instanceof FlinkLogicalCalc) {
+                       FlinkLogicalCalc childCalc = (FlinkLogicalCalc) child;
+                       return findTableFunction(childCalc);
+               }
+               return false;
+       }
+
+       @Override
+       public boolean matches(RelOptRuleCall call) {
+               FlinkLogicalCorrelate correlate = call.rel(0);
+               RelNode right = ((RelSubset) 
correlate.getRight()).getOriginal();
+               if (right instanceof FlinkLogicalTableFunctionScan) {
+                       // right node is a python table function
+                       FlinkLogicalTableFunctionScan scan = 
(FlinkLogicalTableFunctionScan) right;
+                       return PythonUtil.isPythonCall(scan.getCall());
+               } else if (right instanceof FlinkLogicalCalc) {
+                       // a filter is pushed above the table function
+                       return findTableFunction((FlinkLogicalCalc) right);
+               }
+               return false;
+       }
+
+       @Override
+       public RelNode convert(RelNode relNode) {
+               StreamExecPythonCorrelateFactory factory = new 
StreamExecPythonCorrelateFactory(relNode);
+               return factory.convertToCorrelate();
+       }
+
+       /**
+        * The factory is responsible to creating {@link 
StreamExecPythonCorrelate}.
+        */
+       private static class StreamExecPythonCorrelateFactory {
+               private final RelNode correlateRel;
 
 Review comment:
   Remove this member.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to