TsReaper commented on a change in pull request #13742:
URL: https://github.com/apache/flink/pull/13742#discussion_r511699281



##########
File path: 
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/reuse/MultipleInputNodeCreationProcessor.java
##########
@@ -0,0 +1,481 @@
+/*
+ * 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.reuse;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.streaming.api.transformations.ShuffleMode;
+import org.apache.flink.streaming.api.transformations.SourceTransformation;
+import 
org.apache.flink.table.planner.plan.nodes.exec.AbstractExecNodeExactlyOnceVisitor;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecEdge;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNode;
+import 
org.apache.flink.table.planner.plan.nodes.physical.batch.BatchExecBoundedStreamScan;
+import 
org.apache.flink.table.planner.plan.nodes.physical.batch.BatchExecExchange;
+import 
org.apache.flink.table.planner.plan.nodes.physical.batch.BatchExecMultipleInputNode;
+import org.apache.flink.table.planner.plan.nodes.physical.batch.BatchExecUnion;
+import 
org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecDataStreamScan;
+import 
org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecExchange;
+import 
org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecMultipleInputNode;
+import 
org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecUnion;
+import org.apache.flink.table.planner.plan.nodes.process.DAGProcessContext;
+import org.apache.flink.table.planner.plan.nodes.process.DAGProcessor;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.calcite.rel.RelDistribution;
+import org.apache.calcite.rel.RelNode;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.Set;
+
+/**
+ * A {@link DAGProcessor} which organize {@link ExecNode}s into multiple input 
nodes.
+ *
+ * <p>For a detailed explanation of the algorithm, see appendix of the
+ * <a 
href="https://docs.google.com/document/d/1qKVohV12qn-bM51cBZ8Hcgp31ntwClxjoiNBUOqVHsI";>design
 doc</a>.
+ */
+public class MultipleInputNodeCreationProcessor implements DAGProcessor {
+
+       private final boolean isStreaming;
+
+       public MultipleInputNodeCreationProcessor(boolean isStreaming) {
+               this.isStreaming = isStreaming;
+       }
+
+       @Override
+       public List<ExecNode<?, ?>> process(List<ExecNode<?, ?>> sinkNodes, 
DAGProcessContext context) {
+               if (!isStreaming) {
+                       // As multiple input nodes use function call to deliver 
records between sub-operators,
+                       // we cannot rely on network buffers to buffer records 
not yet ready to be read,
+                       // so only BLOCKING dam behavior is safe here.
+                       // If conflict is detected under this stricter 
constraint,
+                       // we add a PIPELINED exchange to mark that its input 
and output node cannot be merged
+                       // into the same multiple input node
+                       InputPriorityConflictResolver resolver = new 
InputPriorityConflictResolver(
+                               sinkNodes,
+                               Collections.emptySet(),
+                               ExecEdge.DamBehavior.BLOCKING,
+                               ShuffleMode.PIPELINED);
+                       resolver.detectAndResolve();
+               }
+
+               List<ExecNodeWrapper> sinkWrappers = wrapExecNodes(sinkNodes);
+               // sort all nodes in topological order, sinks come first and 
sources come last
+               List<ExecNodeWrapper> orderedWrappers = 
topologicalSort(sinkWrappers);
+               // group nodes into multiple input groups
+               createMultipleInputGroups(orderedWrappers);
+               // apply optimizations to remove unnecessary nodes out of 
multiple input groups

Review comment:
       They're best-to-have, not a must.




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


Reply via email to