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/15 01:16:26 UTC

[GitHub] [flink] XuPingyong commented on a change in pull request #8718: [FLINK-12824][table-planner-blink] Set parallelism for stream SQL

XuPingyong commented on a change in pull request #8718: [FLINK-12824][table-planner-blink] Set parallelism for stream SQL
URL: https://github.com/apache/flink/pull/8718#discussion_r294029548
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/plan/nodes/resource/parallelism/FinalParallelismSetter.java
 ##########
 @@ -0,0 +1,135 @@
+/*
+ * 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.parallelism;
+
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.transformations.StreamTransformation;
+import org.apache.flink.table.plan.nodes.exec.ExecNode;
+import org.apache.flink.table.plan.nodes.physical.batch.BatchExecBoundedStreamScan;
+import org.apache.flink.table.plan.nodes.physical.batch.BatchExecTableSourceScan;
+import org.apache.flink.table.plan.nodes.physical.stream.StreamExecDataStreamScan;
+import org.apache.flink.table.plan.nodes.physical.stream.StreamExecTableSourceScan;
+
+import org.apache.calcite.rel.RelDistribution;
+import org.apache.calcite.rel.core.Exchange;
+import org.apache.calcite.rel.core.Values;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Set final parallelism if needed at the beginning time, if parallelism of a node is set to be final,
+ * it will not be changed by other parallelism calculator.
+ */
+public class FinalParallelismSetter {
+
+	private final StreamExecutionEnvironment env;
+	private Set<ExecNode<?, ?>> calculatedNodeSet = new HashSet<>();
+	private Map<ExecNode<?, ?>, Integer> finalParallelismNodeMap = new HashMap<>();
+
+	private FinalParallelismSetter(StreamExecutionEnvironment env) {
+		this.env = env;
+	}
+
+	/**
+	 * Finding nodes that need to set final parallelism.
+	 */
+	public static Map<ExecNode<?, ?>, Integer> calculate(StreamExecutionEnvironment env, List<ExecNode<?, ?>> sinkNodes) {
+		FinalParallelismSetter setter = new FinalParallelismSetter(env);
+		sinkNodes.forEach(setter::calculate);
+		return setter.finalParallelismNodeMap;
+	}
+
+	private void calculate(ExecNode<?, ?> execNode) {
+		if (!calculatedNodeSet.add(execNode)) {
+			return;
+		}
+		if (execNode instanceof BatchExecTableSourceScan) {
+			calculateTableSource((BatchExecTableSourceScan) execNode);
+		} else if (execNode instanceof StreamExecTableSourceScan) {
+			calculateTableSource((StreamExecTableSourceScan) execNode);
+		} else if (execNode instanceof BatchExecBoundedStreamScan) {
+			calculateBoundedStreamScan((BatchExecBoundedStreamScan) execNode);
+		} else if (execNode instanceof StreamExecDataStreamScan) {
+			calculateDataStreamScan((StreamExecDataStreamScan) execNode);
+		} else if (execNode instanceof Values) {
+			calculateValues(execNode);
+		} else {
+			calculateIfSingleton(execNode);
+		}
+	}
+
+	private void calculateTableSource(BatchExecTableSourceScan tableSourceScan) {
+		StreamTransformation transformation = tableSourceScan.getSourceTransformation(env);
+		if (transformation.getMaxParallelism() > 0) {
+			tableSourceScan.getResource().setMaxParallelism(transformation.getMaxParallelism());
 
 Review comment:
   Calculating parallelism of shuffleStage later in ShuffleStageParallelismCalculator considers the max parallelism of exec nodes.

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