Search in sources :

Example 1 with ExecNode

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

the class InputOrderCalculatorTest method testCalculateInputOrderWithUnaffectedRelatedBoundaries.

@Test
public void testCalculateInputOrderWithUnaffectedRelatedBoundaries() {
    // P = InputProperty.DamBehavior.PIPELINED, B = InputProperty.DamBehavior.BLOCKING
    // P1 = PIPELINED + priority 1
    // 
    // 0 --(P0)-> 1 -------(B0)-----> 2 -(P0)-\
    // \          \--(B0)-> 3 -(P1)-/         4
    // \-(B0)-> 5 -------(P1)-----> 6 -(P0)-/
    // 7 --(B0)--/
    TestingBatchExecNode[] nodes = new TestingBatchExecNode[8];
    for (int i = 0; i < nodes.length; i++) {
        nodes[i] = new TestingBatchExecNode("TestingBatchExecNode" + i);
    }
    nodes[1].addInput(nodes[0]);
    nodes[2].addInput(nodes[1], InputProperty.builder().damBehavior(InputProperty.DamBehavior.BLOCKING).build());
    nodes[2].addInput(nodes[3], InputProperty.builder().priority(1).build());
    nodes[3].addInput(nodes[1], InputProperty.builder().damBehavior(InputProperty.DamBehavior.BLOCKING).build());
    nodes[4].addInput(nodes[2]);
    nodes[4].addInput(nodes[6]);
    nodes[5].addInput(nodes[0], InputProperty.builder().damBehavior(InputProperty.DamBehavior.BLOCKING).build());
    nodes[6].addInput(nodes[5], InputProperty.builder().priority(1).build());
    nodes[6].addInput(nodes[7], InputProperty.builder().damBehavior(InputProperty.DamBehavior.BLOCKING).build());
    InputOrderCalculator calculator = new InputOrderCalculator(nodes[4], new HashSet<>(Arrays.asList(nodes[1], nodes[3], nodes[5], nodes[7])), InputProperty.DamBehavior.BLOCKING);
    Map<ExecNode<?>, Integer> result = calculator.calculate();
    Assert.assertEquals(4, result.size());
    Assert.assertEquals(0, result.get(nodes[1]).intValue());
    Assert.assertEquals(1, result.get(nodes[3]).intValue());
    Assert.assertEquals(1, result.get(nodes[5]).intValue());
    Assert.assertEquals(0, result.get(nodes[7]).intValue());
}
Also used : TestingBatchExecNode(org.apache.flink.table.planner.plan.nodes.exec.TestingBatchExecNode) TestingBatchExecNode(org.apache.flink.table.planner.plan.nodes.exec.TestingBatchExecNode) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) Test(org.junit.Test)

Example 2 with ExecNode

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

the class InputOrderCalculatorTest method testCalculateInputOrder.

@Test
public void testCalculateInputOrder() {
    // P = InputProperty.DamBehavior.PIPELINED, B = InputProperty.DamBehavior.BLOCKING
    // P1 = PIPELINED + priority 1
    // 
    // 0 -(P1)-> 3 -(B0)-\
    // 6 -(B0)-\
    // /-(P1)-/         \
    // 1 -(P1)-> 4                  8
    // \-(B0)-\         /
    // 7 -(P1)-/
    // 2 -(P1)-> 5 -(P1)-/
    TestingBatchExecNode[] nodes = new TestingBatchExecNode[9];
    for (int i = 0; i < nodes.length; i++) {
        nodes[i] = new TestingBatchExecNode("TestingBatchExecNode" + i);
    }
    nodes[3].addInput(nodes[0], InputProperty.builder().priority(1).build());
    nodes[4].addInput(nodes[1], InputProperty.builder().priority(1).build());
    nodes[5].addInput(nodes[2], InputProperty.builder().priority(1).build());
    nodes[6].addInput(nodes[3], InputProperty.builder().damBehavior(InputProperty.DamBehavior.BLOCKING).priority(0).build());
    nodes[6].addInput(nodes[4], InputProperty.builder().priority(1).build());
    nodes[7].addInput(nodes[4], InputProperty.builder().damBehavior(InputProperty.DamBehavior.BLOCKING).priority(0).build());
    nodes[7].addInput(nodes[5], InputProperty.builder().priority(1).build());
    nodes[8].addInput(nodes[6], InputProperty.builder().damBehavior(InputProperty.DamBehavior.BLOCKING).priority(0).build());
    nodes[8].addInput(nodes[7], InputProperty.builder().priority(1).build());
    InputOrderCalculator calculator = new InputOrderCalculator(nodes[8], new HashSet<>(Arrays.asList(nodes[1], nodes[3], nodes[5])), InputProperty.DamBehavior.BLOCKING);
    Map<ExecNode<?>, Integer> result = calculator.calculate();
    Assert.assertEquals(3, result.size());
    Assert.assertEquals(0, result.get(nodes[3]).intValue());
    Assert.assertEquals(1, result.get(nodes[1]).intValue());
    Assert.assertEquals(2, result.get(nodes[5]).intValue());
}
Also used : TestingBatchExecNode(org.apache.flink.table.planner.plan.nodes.exec.TestingBatchExecNode) TestingBatchExecNode(org.apache.flink.table.planner.plan.nodes.exec.TestingBatchExecNode) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) Test(org.junit.Test)

Example 3 with ExecNode

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

the class InputPriorityGraphGeneratorTest method testCalculatePipelinedAncestors.

@Test
public void testCalculatePipelinedAncestors() {
    // P = InputProperty.DamBehavior.PIPELINED, E = InputProperty.DamBehavior.END_INPUT
    // 
    // 0 ------P----> 1 -E--> 2
    // \-----P----> 3 -P-/
    // 4 -E-> 5 -P-/ /
    // 6 -----E-----/
    TestingBatchExecNode[] nodes = new TestingBatchExecNode[7];
    for (int i = 0; i < nodes.length; i++) {
        nodes[i] = new TestingBatchExecNode("TestingBatchExecNode" + i);
    }
    nodes[1].addInput(nodes[0]);
    nodes[2].addInput(nodes[1], InputProperty.builder().damBehavior(InputProperty.DamBehavior.END_INPUT).build());
    nodes[2].addInput(nodes[3]);
    nodes[3].addInput(nodes[0]);
    nodes[3].addInput(nodes[5]);
    nodes[3].addInput(nodes[6], InputProperty.builder().damBehavior(InputProperty.DamBehavior.END_INPUT).build());
    nodes[5].addInput(nodes[4], InputProperty.builder().damBehavior(InputProperty.DamBehavior.END_INPUT).build());
    TestingInputPriorityConflictResolver resolver = new TestingInputPriorityConflictResolver(Collections.singletonList(nodes[2]), Collections.emptySet(), InputProperty.DamBehavior.END_INPUT);
    List<ExecNode<?>> ancestors = resolver.calculatePipelinedAncestors(nodes[2]);
    Assert.assertEquals(2, ancestors.size());
    Assert.assertTrue(ancestors.contains(nodes[0]));
    Assert.assertTrue(ancestors.contains(nodes[5]));
}
Also used : TestingBatchExecNode(org.apache.flink.table.planner.plan.nodes.exec.TestingBatchExecNode) TestingBatchExecNode(org.apache.flink.table.planner.plan.nodes.exec.TestingBatchExecNode) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) Test(org.junit.Test)

Example 4 with ExecNode

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

the class JsonPlanGraph method convertToExecNodeGraph.

ExecNodeGraph convertToExecNodeGraph() {
    Map<Integer, ExecNode<?>> idToExecNodes = new HashMap<>();
    for (ExecNode<?> execNode : nodes) {
        int id = execNode.getId();
        if (idToExecNodes.containsKey(id)) {
            throw new TableException(String.format("The id: %s is not unique for ExecNode: %s.\nplease check it.", id, execNode.getDescription()));
        }
        idToExecNodes.put(id, execNode);
    }
    Map<Integer, List<ExecEdge>> idToInputEdges = new HashMap<>();
    Map<Integer, List<ExecEdge>> idToOutputEdges = new HashMap<>();
    for (JsonPlanEdge edge : edges) {
        ExecNode<?> source = idToExecNodes.get(edge.getSourceId());
        if (source == null) {
            throw new TableException(String.format("Source node id: %s is not found in nodes.", edge.getSourceId()));
        }
        ExecNode<?> target = idToExecNodes.get(edge.getTargetId());
        if (target == null) {
            throw new TableException(String.format("Target node id: %s is not found in nodes.", edge.getTargetId()));
        }
        ExecEdge execEdge = ExecEdge.builder().source(source).target(target).shuffle(edge.getShuffle()).exchangeMode(edge.getExchangeMode()).build();
        idToInputEdges.computeIfAbsent(target.getId(), n -> new ArrayList<>()).add(execEdge);
        idToOutputEdges.computeIfAbsent(source.getId(), n -> new ArrayList<>()).add(execEdge);
    }
    List<ExecNode<?>> rootNodes = new ArrayList<>();
    for (Map.Entry<Integer, ExecNode<?>> entry : idToExecNodes.entrySet()) {
        int id = entry.getKey();
        ExecNode<?> node = entry.getValue();
        // connect input edges
        List<ExecEdge> inputEdges = idToInputEdges.getOrDefault(id, new ArrayList<>());
        node.setInputEdges(inputEdges);
        if (!idToOutputEdges.containsKey(id)) {
            // if the node has no output nodes, it's a root node
            rootNodes.add(node);
        }
    }
    return new ExecNodeGraph(flinkVersion, rootNodes);
}
Also used : JsonCreator(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator) Sets(org.apache.flink.shaded.guava30.com.google.common.collect.Sets) ExecNodeVisitorImpl(org.apache.flink.table.planner.plan.nodes.exec.visitor.ExecNodeVisitorImpl) TableException(org.apache.flink.table.api.TableException) Set(java.util.Set) HashMap(java.util.HashMap) JsonProperty(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) ExecNodeVisitor(org.apache.flink.table.planner.plan.nodes.exec.visitor.ExecNodeVisitor) Map(java.util.Map) Internal(org.apache.flink.annotation.Internal) FlinkVersion(org.apache.flink.FlinkVersion) ExecNodeGraph(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeGraph) ExecNodeGraph(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeGraph) TableException(org.apache.flink.table.api.TableException) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ExecNode

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

the class JsonPlanGraph method fromExecNodeGraph.

static JsonPlanGraph fromExecNodeGraph(ExecNodeGraph execGraph) {
    final List<ExecNode<?>> allNodes = new ArrayList<>();
    final List<JsonPlanEdge> allEdges = new ArrayList<>();
    final Set<Integer> nodesIds = new HashSet<>();
    // for quick search
    final Set<ExecNode<?>> visitedNodes = Sets.newIdentityHashSet();
    // visit the nodes as topological ordering
    final ExecNodeVisitor visitor = new ExecNodeVisitorImpl() {

        @Override
        public void visit(ExecNode<?> node) {
            if (visitedNodes.contains(node)) {
                return;
            }
            super.visitInputs(node);
            final int id = node.getId();
            if (nodesIds.contains(id)) {
                throw new TableException(String.format("The id: %s is not unique for ExecNode: %s.\nplease check it.", id, node.getDescription()));
            }
            allNodes.add(node);
            nodesIds.add(id);
            visitedNodes.add(node);
            for (ExecEdge execEdge : node.getInputEdges()) {
                allEdges.add(JsonPlanEdge.fromExecEdge(execEdge));
            }
        }
    };
    execGraph.getRootNodes().forEach(visitor::visit);
    checkArgument(allNodes.size() == nodesIds.size());
    return new JsonPlanGraph(execGraph.getFlinkVersion(), allNodes, allEdges);
}
Also used : TableException(org.apache.flink.table.api.TableException) ExecNodeVisitorImpl(org.apache.flink.table.planner.plan.nodes.exec.visitor.ExecNodeVisitorImpl) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) ArrayList(java.util.ArrayList) ExecNodeVisitor(org.apache.flink.table.planner.plan.nodes.exec.visitor.ExecNodeVisitor) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) HashSet(java.util.HashSet)

Aggregations

ExecNode (org.apache.flink.table.planner.plan.nodes.exec.ExecNode)17 ArrayList (java.util.ArrayList)8 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)7 TestingBatchExecNode (org.apache.flink.table.planner.plan.nodes.exec.TestingBatchExecNode)6 Test (org.junit.Test)6 InputProperty (org.apache.flink.table.planner.plan.nodes.exec.InputProperty)5 AbstractExecNodeExactlyOnceVisitor (org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor)5 HashSet (java.util.HashSet)4 ExecNodeVisitor (org.apache.flink.table.planner.plan.nodes.exec.visitor.ExecNodeVisitor)4 TableException (org.apache.flink.table.api.TableException)3 ExecNodeVisitorImpl (org.apache.flink.table.planner.plan.nodes.exec.visitor.ExecNodeVisitorImpl)3 HashMap (java.util.HashMap)2 ExecNodeGraph (org.apache.flink.table.planner.plan.nodes.exec.ExecNodeGraph)2 BatchExecNode (org.apache.flink.table.planner.plan.nodes.exec.batch.BatchExecNode)2 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1