use of org.apache.flink.table.planner.plan.nodes.exec.common.CommonExecSink in project flink by apache.
the class ExecNodePlanDumper method dagToString.
/**
* Converts an {@link ExecNode} DAG to a string as a tree style.
*
* <p>The following DAG of {@link ExecNode}
*
* <pre>{@code
* Sink1 Sink2
* | |
* Filter3 Filter4
* \ /
* Join
* / \
* Filter1 Filter2
* \ /
* Project
* |
* Scan
* }</pre>
*
* <p>would be converted to the tree style as following:
*
* <pre>{@code
* Join(reuse_id=[2])
* :- Filter1
* : +- Project(reuse_id=[1])
* : +- Scan
* +- Filter2
* +- Reused(reference_id=[1])
*
* Sink1
* +- Filter3
* +- Reused(reference_id=[2])
*
* Sink2
* +- Filter4
* +- Reused(reference_id=[2])
* }</pre>
*
* @param nodes the ExecNodes to convert
* @return the plan of ExecNode
*/
public static String dagToString(List<ExecNode<?>> nodes) {
Preconditions.checkArgument(nodes != null && !nodes.isEmpty(), "nodes should not be null or empty.");
if (nodes.size() == 1) {
return treeToString(nodes.get(0));
}
// nodes that stop visit when meet them
final List<ExecNode<?>> stopVisitNodes = new ArrayList<>();
final StringBuilder sb = new StringBuilder();
final DagReuseInfo reuseInfo = new DagReuseInfo(nodes, new ArrayList<>());
final ExecNodeVisitor visitor = new ExecNodeVisitorImpl() {
@Override
public void visit(ExecNode<?> node) {
int visitedTimes = reuseInfo.addVisitedTimes(node);
boolean isFirstVisit = visitedTimes == 1;
if (isFirstVisit) {
super.visit(node);
}
int reuseId = reuseInfo.getReuseId(node);
boolean isReuseNode = reuseId >= 0;
if (node instanceof CommonExecLegacySink || node instanceof CommonExecSink || (isReuseNode && isFirstVisit)) {
if (isReuseNode) {
reuseInfo.setFirstVisited(node, true);
}
String reusePlan = doConvertTreeToString(node, reuseInfo, false, stopVisitNodes, false);
sb.append(reusePlan).append(System.lineSeparator());
if (isReuseNode) {
// update visit info after the reuse node visited
stopVisitNodes.add(node);
reuseInfo.setFirstVisited(node, false);
}
}
}
};
nodes.forEach(visitor::visit);
if (sb.length() > 0) {
// delete last line separator
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString();
}
Aggregations