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_r379243229
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/rules/physical/batch/BatchExecPythonCorrelateRule.java
 ##########
 @@ -0,0 +1,125 @@
+/*
+ * 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.batch;
+
+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.batch.BatchExecPythonCorrelate;
+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 BatchExecPythonCorrelate}.
+ */
+public class BatchExecPythonCorrelateRule extends ConverterRule {
+
+       public static final RelOptRule INSTANCE = new 
BatchExecPythonCorrelateRule();
+
+       private BatchExecPythonCorrelateRule() {
+               super(FlinkLogicalCorrelate.class, FlinkConventions.LOGICAL(), 
FlinkConventions.BATCH_PHYSICAL(),
+                       "BatchExecPythonCorrelateRule");
+       }
+
+       @Override
+       public boolean matches(RelOptRuleCall call) {
+               FlinkLogicalCorrelate join = call.rel(0);
+               RelNode right = ((RelSubset) join.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
+                       FlinkLogicalCalc calc = (FlinkLogicalCalc) right;
+                       RelSubset input = (RelSubset) calc.getInput();
+                       FlinkLogicalTableFunctionScan scan = 
(FlinkLogicalTableFunctionScan) input.getOriginal();
+                       return PythonUtil.isPythonCall(scan.getCall());
+               }
+               return false;
+       }
+
+       @Override
+       public RelNode convert(RelNode relNode) {
+               BatchExecPythonCorrelateFactory factory = new 
BatchExecPythonCorrelateFactory(relNode);
+               return factory.convertToCorrelate();
+       }
+
+       /**
+        * The factory is responsible to creating {@link 
BatchExecPythonCorrelate}.
+        */
+       private static class BatchExecPythonCorrelateFactory {
+               private final RelNode correlateRel;
+               private final FlinkLogicalCorrelate correlate;
+               private final RelTraitSet traitSet;
+               private final RelNode convInput;
+               private final RelNode right;
+
+               BatchExecPythonCorrelateFactory(RelNode rel) {
+                       this.correlateRel = rel;
 
 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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to