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 2020/12/10 03:16:52 UTC

[GitHub] [flink] godfreyhe commented on a change in pull request #14315: [FLINK-20478][table-planner-blink] Adjust the explain result for blink planner

godfreyhe commented on a change in pull request #14315:
URL: https://github.com/apache/flink/pull/14315#discussion_r539813438



##########
File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/utils/ExecNodePlanDumper.java
##########
@@ -0,0 +1,391 @@
+/*
+ * 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.utils;
+
+import org.apache.flink.table.planner.plan.nodes.calcite.LegacySink;
+import org.apache.flink.table.planner.plan.nodes.calcite.Sink;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNode;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeVisitor;
+import org.apache.flink.table.planner.plan.nodes.exec.ExecNodeVisitorImpl;
+import org.apache.flink.table.planner.plan.nodes.physical.FlinkPhysicalRel;
+import org.apache.flink.util.Preconditions;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * An utility class for converting an exec node plan to a string as a tree style.
+ */
+public class ExecNodePlanDumper {
+
+	/**
+	 * Converts an {@link ExecNode} tree to a string as a tree style.
+	 *
+	 * @param node the ExecNode to convert
+	 * @return explain plan of ExecNode
+	 *
+	 * <p> The following tree of {@link ExecNode}
+	 * <pre>{@code
+	 *        Sink
+	 *         |
+	 *        Join
+	 *      /      \
+	 *  Filter1  Filter2
+	 *     \     /
+	 *    Project1
+	 *       |
+	 *     Scan
+	 * }</pre>
+	 *
+	 * would be converted to the tree style as following:
+	 * <pre>{@code
+	 * Sink
+	 * +- Join
+	 *    :- Filter1
+	 *    :  +- Project1(reuse_id=[1])
+	 *    :     +- Scan
+	 *    +- Filter2
+	 *       +- Reused(reference_id=[1])
+	 * }
+	 * }</pre>
+	 */
+	public static String treeToString(ExecNode<?> node) {
+		return treeToString(node, new ArrayList<>(), false);
+	}
+
+	/**
+	 * Converts an {@link ExecNode} tree to a string as a tree style.
+	 *
+	 * @param node the ExecNode to convert
+	 * @param borders node sets that stop visit when meet them
+	 * @param includingBorders Whether print the border nodes
+	 * @return the plan of ExecNode
+	 */
+	public static String treeToString(ExecNode<?> node, List<ExecNode<?>> borders, boolean includingBorders) {
+		checkNotNull(node, "node should not be null.");
+		// convert to mutable list
+		List<ExecNode<?>> borderList = new ArrayList<>(checkNotNull(borders, "borders should not be null."));
+		TreeReuseInfo reuseInfo = new TreeReuseInfo(node, borderList);
+		return doConvertTreeToString(node, reuseInfo, true, borderList, includingBorders);
+	}
+
+	/**
+	 * Converts an {@link ExecNode} DAG to a string as a tree style.
+	 *
+	 * @param nodes the ExecNodes to convert
+	 * @return the plan of ExecNode
+	 *
+	 * <p> The following DAG of {@link ExecNode}
+	 * <pre>{@code
+	 *     Sink1    Sink2
+	 *      |        |
+	 *   Filter3  Filter4
+	 *       \     /
+	 *        Join
+	 *      /      \
+	 *  Filter1  Filter2
+	 *     \     /
+	 *    Project1
+	 *       |
+	 *     Scan
+	 * }</pre>
+	 *
+	 * would be converted to the tree style as following:
+	 * <pre>{@code

Review comment:
       how to display the reused (common) plan ? If  the result of the example just contains two trees, each tree will display all nodes from sink to source.




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