use of org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecNode in project flink by apache.
the class ForwardHashExchangeProcessor method process.
@Override
public ExecNodeGraph process(ExecNodeGraph execGraph, ProcessorContext context) {
if (execGraph.getRootNodes().get(0) instanceof StreamExecNode) {
throw new TableException("StreamExecNode is not supported yet");
}
if (!context.getPlanner().getExecEnv().getConfig().isDynamicGraph()) {
return execGraph;
}
ExecNodeVisitor visitor = new AbstractExecNodeExactlyOnceVisitor() {
@Override
protected void visitNode(ExecNode<?> node) {
visitInputs(node);
if (node instanceof CommonExecExchange) {
return;
}
boolean changed = false;
List<ExecEdge> newEdges = new ArrayList<>(node.getInputEdges());
for (int i = 0; i < node.getInputProperties().size(); ++i) {
InputProperty inputProperty = node.getInputProperties().get(i);
RequiredDistribution requiredDistribution = inputProperty.getRequiredDistribution();
ExecEdge edge = node.getInputEdges().get(i);
if (requiredDistribution.getType() == DistributionType.SINGLETON) {
if (!hasExchangeInput(edge) && isInputSortedNode(node)) {
// if operation chaining is disabled, this could mark sure the
// sort node and its output can also be connected by
// ForwardPartitioner
ExecEdge newEdge = addExchangeAndReconnectEdge(edge, inputProperty, true);
newEdges.set(i, newEdge);
changed = true;
}
continue;
}
if (requiredDistribution.getType() != DistributionType.HASH) {
continue;
}
if (!hasExchangeInput(edge)) {
ExecEdge newEdge;
if (isInputSortedNode(node)) {
if (hasSortInputForInputSortedNode(node)) {
// add Exchange with keep_input_as_is distribution as the
// input of Sort
ExecNode<?> sort = edge.getSource();
ExecEdge newEdgeOfSort = addExchangeAndReconnectEdge(sort.getInputEdges().get(0), inputProperty, false);
sort.setInputEdges(Collections.singletonList(newEdgeOfSort));
}
// if operation chaining is disabled, this could mark sure the
// sort node and its output can also be connected by
// ForwardPartitioner
newEdge = addExchangeAndReconnectEdge(edge, inputProperty, true);
} else {
// add Exchange with keep_input_as_is distribution as the input
// of the node
newEdge = addExchangeAndReconnectEdge(edge, inputProperty, false);
updateOriginalEdgeInMultipleInput(node, i, (BatchExecExchange) newEdge.getSource());
}
// update the edge
newEdges.set(i, newEdge);
changed = true;
} else if (hasSortInputForInputSortedNode(node)) {
// if operation chaining is disabled, this could mark sure the sort
// node and its output can also be connected by ForwardPartitioner
ExecEdge newEdge = addExchangeAndReconnectEdge(edge, inputProperty, true);
newEdges.set(i, newEdge);
changed = true;
}
}
if (changed) {
node.setInputEdges(newEdges);
}
}
};
execGraph.getRootNodes().forEach(s -> s.accept(visitor));
return execGraph;
}
Aggregations