You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/06/11 15:51:18 UTC

[GitHub] [flink] XuPingyong commented on a change in pull request #8690: [FLINK-12801][table-planner-blink] set parallelism for batch SQL

XuPingyong commented on a change in pull request #8690: [FLINK-12801][table-planner-blink] set parallelism for batch SQL
URL: https://github.com/apache/flink/pull/8690#discussion_r292530539
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/plan/nodes/resource/batch/parallelism/ShuffleStageGenerator.java
 ##########
 @@ -0,0 +1,146 @@
+/*
+ * 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.plan.nodes.resource.batch.parallelism;
+
+import org.apache.flink.table.plan.nodes.exec.ExecNode;
+import org.apache.flink.table.plan.nodes.physical.batch.BatchExecExchange;
+import org.apache.flink.table.plan.nodes.physical.batch.BatchExecSink;
+import org.apache.flink.table.plan.nodes.physical.batch.BatchExecUnion;
+
+import org.apache.calcite.rel.RelDistribution;
+
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static java.util.stream.Collectors.toList;
+
+/**
+ * Build shuffleStages.
+ */
+public class ShuffleStageGenerator {
+
+	private final Map<ExecNode<?, ?>, ShuffleStage> nodeShuffleStageMap = new LinkedHashMap<>();
+	private final Map<ExecNode<?, ?>, Integer> nodeToFinalParallelismMap;
+
+	private ShuffleStageGenerator(Map<ExecNode<?, ?>, Integer> nodeToFinalParallelismMap) {
+		this.nodeToFinalParallelismMap = nodeToFinalParallelismMap;
+	}
+
+	public static Map<ExecNode<?, ?>, ShuffleStage> generate(List<ExecNode<?, ?>> sinkNodes, Map<ExecNode<?, ?>, Integer> finalParallelismNodeMap) {
+		ShuffleStageGenerator generator = new ShuffleStageGenerator(finalParallelismNodeMap);
+		sinkNodes.forEach(generator::buildShuffleStages);
+		Map<ExecNode<?, ?>, ShuffleStage> result = generator.getNodeShuffleStageMap();
+		result.values().forEach(s -> {
+			List<ExecNode<?, ?>> virtualNodeList = s.getExecNodeSet().stream().filter(ShuffleStageGenerator::isVirtualNode).collect(toList());
+			virtualNodeList.forEach(s::removeNode);
+		});
+		return generator.getNodeShuffleStageMap().entrySet().stream()
+				.filter(x -> !isVirtualNode(x.getKey()))
+				.collect(Collectors.toMap(Map.Entry::getKey,
+						Map.Entry::getValue,
+						(e1, e2) -> e1,
+						LinkedHashMap::new));
+	}
+
+	private void buildShuffleStages(ExecNode<?, ?> execNode) {
+		if (nodeShuffleStageMap.containsKey(execNode)) {
+			return;
+		}
+		for (ExecNode<?, ?> input : execNode.getInputNodes()) {
+			buildShuffleStages((input));
+		}
+
+		if (execNode.getInputNodes().isEmpty()) {
+			// source node
+			ShuffleStage shuffleStage = new ShuffleStage();
+			shuffleStage.addNode(execNode);
+			if (nodeToFinalParallelismMap.containsKey(execNode)) {
+				shuffleStage.setParallelism(nodeToFinalParallelismMap.get(execNode), true);
+			}
+			nodeShuffleStageMap.put(execNode, shuffleStage);
+		} else if (execNode instanceof BatchExecExchange && !(((BatchExecExchange) execNode).getDistribution().getType() == RelDistribution.Type.RANGE_DISTRIBUTED)) {
+			// do nothing
+		} else if (execNode instanceof BatchExecSink) {
 
 Review comment:
   > Here you consider `BatchExecSink`, and you exclude `BatchExecSink` before?
   
   Double exclude, I fix it.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services