Search in sources :

Example 1 with AbstractExecNodeExactlyOnceVisitor

use of org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor in project flink by apache.

the class InputOrderCalculator method calculateAllAncestors.

private static Set<ExecNode<?>> calculateAllAncestors(ExecNode<?> node) {
    Set<ExecNode<?>> ret = new HashSet<>();
    AbstractExecNodeExactlyOnceVisitor visitor = new AbstractExecNodeExactlyOnceVisitor() {

        @Override
        protected void visitNode(ExecNode<?> node) {
            ret.add(node);
            visitInputs(node);
        }
    };
    node.accept(visitor);
    return ret;
}
Also used : AbstractExecNodeExactlyOnceVisitor(org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) HashSet(java.util.HashSet)

Example 2 with AbstractExecNodeExactlyOnceVisitor

use of org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor in project flink by apache.

the class MultipleInputNodeCreationProcessor method wrapExecNodes.

// --------------------------------------------------------------------------------
// Wrapping and Sorting
// --------------------------------------------------------------------------------
private List<ExecNodeWrapper> wrapExecNodes(List<ExecNode<?>> rootNodes) {
    Map<ExecNode<?>, ExecNodeWrapper> wrapperMap = new HashMap<>();
    AbstractExecNodeExactlyOnceVisitor visitor = new AbstractExecNodeExactlyOnceVisitor() {

        @Override
        protected void visitNode(ExecNode<?> node) {
            ExecNodeWrapper wrapper = wrapperMap.computeIfAbsent(node, k -> new ExecNodeWrapper(node));
            for (ExecEdge inputEdge : node.getInputEdges()) {
                ExecNode<?> inputNode = inputEdge.getSource();
                ExecNodeWrapper inputWrapper = wrapperMap.computeIfAbsent(inputNode, k -> new ExecNodeWrapper(inputNode));
                wrapper.inputs.add(inputWrapper);
                inputWrapper.outputs.add(wrapper);
            }
            visitInputs(node);
        }
    };
    rootNodes.forEach(s -> s.accept(visitor));
    List<ExecNodeWrapper> rootWrappers = new ArrayList<>();
    for (ExecNode<?> root : rootNodes) {
        ExecNodeWrapper rootWrapper = wrapperMap.get(root);
        Preconditions.checkNotNull(rootWrapper, "Root node is not wrapped. This is a bug.");
        rootWrappers.add(rootWrapper);
    }
    return rootWrappers;
}
Also used : AbstractExecNodeExactlyOnceVisitor(org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode)

Example 3 with AbstractExecNodeExactlyOnceVisitor

use of org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor 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;
}
Also used : AbstractExecNodeExactlyOnceVisitor(org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor) RequiredDistribution(org.apache.flink.table.planner.plan.nodes.exec.InputProperty.RequiredDistribution) TableException(org.apache.flink.table.api.TableException) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) ArrayList(java.util.ArrayList) StreamExecNode(org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecNode) CommonExecExchange(org.apache.flink.table.planner.plan.nodes.exec.common.CommonExecExchange) ExecNodeVisitor(org.apache.flink.table.planner.plan.nodes.exec.visitor.ExecNodeVisitor) InputSortedExecNode(org.apache.flink.table.planner.plan.nodes.exec.batch.InputSortedExecNode) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) StreamExecNode(org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecNode)

Example 4 with AbstractExecNodeExactlyOnceVisitor

use of org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor in project flink by apache.

the class InputPriorityGraphGenerator method createTopologyGraph.

protected void createTopologyGraph() {
    // build an initial topology graph
    graph = new TopologyGraph(roots, boundaries);
    // check and resolve conflicts about input priorities
    AbstractExecNodeExactlyOnceVisitor inputPriorityVisitor = new AbstractExecNodeExactlyOnceVisitor() {

        @Override
        protected void visitNode(ExecNode<?> node) {
            if (!boundaries.contains(node)) {
                visitInputs(node);
            }
            updateTopologyGraph(node);
        }
    };
    roots.forEach(n -> n.accept(inputPriorityVisitor));
}
Also used : AbstractExecNodeExactlyOnceVisitor(org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor) BatchExecNode(org.apache.flink.table.planner.plan.nodes.exec.batch.BatchExecNode) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode)

Example 5 with AbstractExecNodeExactlyOnceVisitor

use of org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor in project flink by apache.

the class InputPriorityGraphGenerator method calculatePipelinedAncestors.

/**
 * Find the ancestors by going through PIPELINED edges.
 */
@VisibleForTesting
List<ExecNode<?>> calculatePipelinedAncestors(ExecNode<?> node) {
    List<ExecNode<?>> ret = new ArrayList<>();
    AbstractExecNodeExactlyOnceVisitor ancestorVisitor = new AbstractExecNodeExactlyOnceVisitor() {

        @Override
        protected void visitNode(ExecNode<?> node) {
            boolean hasAncestor = false;
            if (!boundaries.contains(node)) {
                List<InputProperty> inputProperties = node.getInputProperties();
                for (int i = 0; i < inputProperties.size(); i++) {
                    // we only go through PIPELINED edges
                    if (inputProperties.get(i).getDamBehavior().stricterOrEqual(safeDamBehavior)) {
                        continue;
                    }
                    hasAncestor = true;
                    node.getInputEdges().get(i).getSource().accept(this);
                }
            }
            if (!hasAncestor) {
                ret.add(node);
            }
        }
    };
    node.accept(ancestorVisitor);
    return ret;
}
Also used : AbstractExecNodeExactlyOnceVisitor(org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) ArrayList(java.util.ArrayList) BatchExecNode(org.apache.flink.table.planner.plan.nodes.exec.batch.BatchExecNode) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

ExecNode (org.apache.flink.table.planner.plan.nodes.exec.ExecNode)5 AbstractExecNodeExactlyOnceVisitor (org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor)5 ArrayList (java.util.ArrayList)3 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)2 InputProperty (org.apache.flink.table.planner.plan.nodes.exec.InputProperty)2 BatchExecNode (org.apache.flink.table.planner.plan.nodes.exec.batch.BatchExecNode)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 TableException (org.apache.flink.table.api.TableException)1 RequiredDistribution (org.apache.flink.table.planner.plan.nodes.exec.InputProperty.RequiredDistribution)1 InputSortedExecNode (org.apache.flink.table.planner.plan.nodes.exec.batch.InputSortedExecNode)1 CommonExecExchange (org.apache.flink.table.planner.plan.nodes.exec.common.CommonExecExchange)1 StreamExecNode (org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecNode)1 ExecNodeVisitor (org.apache.flink.table.planner.plan.nodes.exec.visitor.ExecNodeVisitor)1