beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (BEAM-3193) CoGroupByKey doesn't work in streaming mode
Date Mon, 03 Sep 2018 08:56:00 GMT

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

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

                Author: ASF GitHub Bot
            Created on: 03/Sep/18 08:55
            Start Date: 03/Sep/18 08:55
    Worklog Time Spent: 10m 
      Work Description: aromanenko-dev commented on a change in pull request #5945: [BEAM-3193]
Add SparkCoGroupByKeyStreaming validates runner to test CoGroupByKay bahavior in streaming
mode on spark runner
URL: https://github.com/apache/beam/pull/5945#discussion_r214617572
 
 

 ##########
 File path: runners/spark/src/test/java/org/apache/beam/runners/spark/translation/streaming/SparkCoGroupByKeyStreamingTest.java
 ##########
 @@ -0,0 +1,152 @@
+/*
+ * 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.spark.translation.streaming;
+
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import com.google.common.collect.Iterables;
+import org.apache.beam.runners.spark.ReuseSparkContextRule;
+import org.apache.beam.runners.spark.SparkPipelineOptions;
+import org.apache.beam.runners.spark.StreamingTest;
+import org.apache.beam.runners.spark.io.CreateStream;
+import org.apache.beam.sdk.coders.KvCoder;
+import org.apache.beam.sdk.coders.VarIntCoder;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.transforms.SerializableFunction;
+import org.apache.beam.sdk.transforms.join.CoGbkResult;
+import org.apache.beam.sdk.transforms.join.CoGroupByKey;
+import org.apache.beam.sdk.transforms.join.KeyedPCollectionTuple;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.TimestampedValue;
+import org.apache.beam.sdk.values.TupleTag;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/** A test that verifies that CoGroupByKey works in streaming mode in spark runner. */
+public class SparkCoGroupByKeyStreamingTest {
+
+  private static final TupleTag<Integer> INPUT1_TAG = new TupleTag<>("input1");
+  private static final TupleTag<Integer> INPUT2_TAG = new TupleTag<>("input2");
+
+  @Rule public final transient ReuseSparkContextRule noContextResue = ReuseSparkContextRule.no();
+
+  @Rule public final TestPipeline pipeline = TestPipeline.create();
+
+  private Duration batchDuration() {
+    return Duration.millis(
+        (pipeline.getOptions().as(SparkPipelineOptions.class)).getBatchIntervalMillis());
+  }
+
+  @Category(StreamingTest.class)
+  @Test
+  public void testInStreamingMode() throws Exception {
+    Instant instant = new Instant(0);
+    CreateStream<KV<Integer, Integer>> source1 =
+        CreateStream.of(KvCoder.of(VarIntCoder.of(), VarIntCoder.of()), batchDuration())
+            .emptyBatch()
+            .advanceWatermarkForNextBatch(instant)
+            .nextBatch(
+                TimestampedValue.of(KV.of(1, 1), instant),
+                TimestampedValue.of(KV.of(1, 2), instant),
+                TimestampedValue.of(KV.of(1, 3), instant))
+            .advanceWatermarkForNextBatch(instant.plus(Duration.standardSeconds(1L)))
+            .nextBatch(
+                TimestampedValue.of(KV.of(2, 4), instant.plus(Duration.standardSeconds(1L))),
+                TimestampedValue.of(KV.of(2, 5), instant.plus(Duration.standardSeconds(1L))),
+                TimestampedValue.of(KV.of(2, 6), instant.plus(Duration.standardSeconds(1L))))
+            .advanceNextBatchWatermarkToInfinity();
+
+    CreateStream<KV<Integer, Integer>> source2 =
+        CreateStream.of(KvCoder.of(VarIntCoder.of(), VarIntCoder.of()), batchDuration())
+            .emptyBatch()
+            .advanceWatermarkForNextBatch(instant)
+            .nextBatch(
+                TimestampedValue.of(KV.of(1, 11), instant),
+                TimestampedValue.of(KV.of(1, 12), instant),
+                TimestampedValue.of(KV.of(1, 13), instant))
+            .advanceWatermarkForNextBatch(instant.plus(Duration.standardSeconds(1L)))
+            .nextBatch(
+                TimestampedValue.of(KV.of(2, 14), instant.plus(Duration.standardSeconds(1L))),
+                TimestampedValue.of(KV.of(2, 15), instant.plus(Duration.standardSeconds(1L))),
+                TimestampedValue.of(KV.of(2, 16), instant.plus(Duration.standardSeconds(1L))))
+            .advanceNextBatchWatermarkToInfinity();
+
+    PCollection<KV<Integer, Integer>> input1 =
+        pipeline
+            .apply("create source1", source1)
+            .apply(
+                "window input1",
+                Window.<KV<Integer, Integer>>into(FixedWindows.of(Duration.standardSeconds(3L)))
+                    .withAllowedLateness(Duration.ZERO));
+
+    PCollection<KV<Integer, Integer>> input2 =
+        pipeline
+            .apply("create source2", source2)
+            .apply(
+                "window input2",
+                Window.<KV<Integer, Integer>>into(FixedWindows.of(Duration.standardSeconds(3L)))
+                    .withAllowedLateness(Duration.ZERO));
+
+    PCollection<KV<Integer, CoGbkResult>> output =
+        KeyedPCollectionTuple.of(INPUT1_TAG, input1)
+            .and(INPUT2_TAG, input2)
+            .apply(CoGroupByKey.create());
+    PAssert.that("Wrong output of the join using CoGroupByKey in streaming mode", output)
+        .satisfies(
+            (SerializableFunction<Iterable<KV<Integer, CoGbkResult>>, Void>)
+                input -> {
+                  assertEquals("Wrong size of the output PCollection", 2, Iterables.size(input));
+                  for (KV<Integer, CoGbkResult> element : input) {
+                    if (element.getKey() == 1) {
+                      assertThat(
 
 Review comment:
   I think we have to assert the size of collections of values as well (equal to 6) to guarantee
that there are no other values that we don't expect. 

----------------------------------------------------------------
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:
users@infra.apache.org


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

    Worklog Id:     (was: 140505)
    Time Spent: 2h 10m  (was: 2h)

> CoGroupByKey doesn't work in streaming mode
> -------------------------------------------
>
>                 Key: BEAM-3193
>                 URL: https://issues.apache.org/jira/browse/BEAM-3193
>             Project: Beam
>          Issue Type: Bug
>          Components: runner-spark
>            Reporter: Jean-Baptiste Onofré
>            Assignee: Etienne Chauchot
>            Priority: Major
>          Time Spent: 2h 10m
>  Remaining Estimate: 0h
>
> The CoGroupByKey PTransform doesn't throw an exception but doesn't actually perform the
grouping when used in streaming mode. I will attach a test pipeline.



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

Mime
View raw message