[ 
https://issues.apache.org/jira/browse/BEAM-3914?focusedWorklogId=94881&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-94881
 ]

ASF GitHub Bot logged work on BEAM-3914:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Apr/18 00:03
            Start Date: 25/Apr/18 00:03
    Worklog Time Spent: 10m 
      Work Description: robertwb commented on a change in pull request #4977: 
[BEAM-3914] Deduplicate Unzipped Flattens after Pipeline Fusion
URL: https://github.com/apache/beam/pull/4977#discussion_r183911633
 
 

 ##########
 File path: 
runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/graph/OutputDeduplicatorTest.java
 ##########
 @@ -0,0 +1,438 @@
+/*
+ * 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.beam.runners.core.construction.graph;
+
+import static com.google.common.collect.Iterables.getOnlyElement;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.Assert.assertThat;
+
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.beam.model.pipeline.v1.RunnerApi;
+import org.apache.beam.model.pipeline.v1.RunnerApi.Components;
+import org.apache.beam.model.pipeline.v1.RunnerApi.Environment;
+import org.apache.beam.model.pipeline.v1.RunnerApi.PCollection;
+import org.apache.beam.model.pipeline.v1.RunnerApi.PTransform;
+import 
org.apache.beam.runners.core.construction.graph.OutputDeduplicator.DeduplicationResult;
+import 
org.apache.beam.runners.core.construction.graph.PipelineNode.PCollectionNode;
+import 
org.apache.beam.runners.core.construction.graph.PipelineNode.PTransformNode;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link OutputDeduplicator}. */
+@RunWith(JUnit4.class)
+public class OutputDeduplicatorTest {
+  @Test
+  public void unchangedWithNoDuplicates() {
+    /* When all the PCollections are produced by only one transform or stage, 
the result should be
+     * empty//identical to the input.
+     */
+    PTransform one =
+        PTransform.newBuilder().putInputs("in", "red.out").putOutputs("out", 
"one.out").build();
+    PCollection oneOut = 
PCollection.newBuilder().setUniqueName("one.out").build();
+    PTransform two =
+        PTransform.newBuilder().putInputs("in", "red.out").putOutputs("out", 
"two.out").build();
+    PCollection twoOut = 
PCollection.newBuilder().setUniqueName("two.out").build();
+    PTransform red = PTransform.newBuilder().putOutputs("out", 
"red.out").build();
+    PCollection redOut = 
PCollection.newBuilder().setUniqueName("red.out").build();
+    PTransform blue =
+        PTransform.newBuilder()
+            .putInputs("one", "one.out")
+            .putInputs("two", "two.out")
+            .putOutputs("out", "blue.out")
+            .build();
+    PCollection blueOut = 
PCollection.newBuilder().setUniqueName("blue.out").build();
+    RunnerApi.Components components =
+        Components.newBuilder()
+            .putTransforms("one", one)
+            .putPcollections("one.out", oneOut)
+            .putTransforms("two", two)
+            .putPcollections("two.out", twoOut)
+            .putTransforms("red", red)
+            .putPcollections("red.out", redOut)
+            .putTransforms("blue", blue)
+            .putPcollections("blue.out", blueOut)
+            .build();
+    ExecutableStage oneStage =
+        ImmutableExecutableStage.of(
+            components,
+            Environment.getDefaultInstance(),
+            PipelineNode.pCollection("red.out", redOut),
+            ImmutableList.of(),
+            ImmutableList.of(PipelineNode.pTransform("one", one)),
+            ImmutableList.of(PipelineNode.pCollection("one.out", oneOut)));
+    ExecutableStage twoStage =
+        ImmutableExecutableStage.of(
+            components,
+            Environment.getDefaultInstance(),
+            PipelineNode.pCollection("red.out", redOut),
+            ImmutableList.of(),
+            ImmutableList.of(PipelineNode.pTransform("two", two)),
+            ImmutableList.of(PipelineNode.pCollection("two.out", twoOut)));
+    PTransformNode redTransform = PipelineNode.pTransform("red", red);
+    PTransformNode blueTransform = PipelineNode.pTransform("blue", blue);
+    QueryablePipeline pipeline = QueryablePipeline.forPrimitivesIn(components);
+    DeduplicationResult result =
+        OutputDeduplicator.ensureSingleProducer(
+            pipeline,
+            ImmutableList.of(oneStage, twoStage),
+            ImmutableList.of(redTransform, blueTransform));
+
+    assertThat(result.getDeduplicatedComponents(), equalTo(components));
+    assertThat(result.getDeduplicatedStages().keySet(), empty());
+    assertThat(result.getDeduplicatedTransforms().keySet(), empty());
+    assertThat(result.getIntroducedTransforms(), empty());
+  }
+
+  @Test
+  public void duplicateOverStages() {
+    /* When multiple stages and a runner-executed transform produce a 
PCollection, all should be
+     * replaced with synthetic flattens.
+     * S -> A; T -> A becomes S -> A'; T -> A''; A', A'' -> Flatten -> A
 
 Review comment:
   Same. Or use red, blue, one, two in your example here. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 94881)
    Time Spent: 3h  (was: 2h 50m)

> 'Unzip' flattens before performing fusion
> -----------------------------------------
>
>                 Key: BEAM-3914
>                 URL: https://issues.apache.org/jira/browse/BEAM-3914
>             Project: Beam
>          Issue Type: Improvement
>          Components: runner-core
>            Reporter: Thomas Groh
>            Assignee: Thomas Groh
>            Priority: Major
>              Labels: portability
>          Time Spent: 3h
>  Remaining Estimate: 0h
>
> This consists of duplicating nodes downstream of a flatten that exist within 
> an environment, and reintroducing the flatten immediately upstream of a 
> runner-executed transform (the flatten should be executed within the runner)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to