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

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

                Author: ASF GitHub Bot
            Created on: 07/Feb/19 11:07
            Start Date: 07/Feb/19 11:07
    Worklog Time Spent: 10m 
      Work Description: iemejia commented on pull request #7601: [BEAM-5392] 
GroupByKey optimized for non-merging windows
URL: https://github.com/apache/beam/pull/7601#discussion_r254636383
 
 

 ##########
 File path: 
runners/spark/src/test/java/org/apache/beam/runners/spark/translation/GroupNonMergingWindowsFunctionsTest.java
 ##########
 @@ -0,0 +1,133 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.beam.runners.spark.coders.CoderHelpers;
+import 
org.apache.beam.runners.spark.translation.GroupNonMergingWindowsFunctions.GroupByKeyIterator;
+import 
org.apache.beam.runners.spark.translation.GroupNonMergingWindowsFunctions.WindowedKey;
+import org.apache.beam.sdk.coders.BigEndianIntegerCoder;
+import org.apache.beam.sdk.coders.ByteArrayCoder;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.StringUtf8Coder;
+import org.apache.beam.sdk.transforms.windowing.GlobalWindow;
+import org.apache.beam.sdk.transforms.windowing.GlobalWindows;
+import org.apache.beam.sdk.transforms.windowing.PaneInfo;
+import org.apache.beam.sdk.util.WindowedValue;
+import org.apache.beam.sdk.util.WindowedValue.FullWindowedValueCoder;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.WindowingStrategy;
+import org.joda.time.Instant;
+import org.junit.Assert;
+import org.junit.Test;
+import scala.Tuple2;
+
+/** Unit tests of {@link GroupNonMergingWindowsFunctions}. */
+public class GroupNonMergingWindowsFunctionsTest {
+
+  @Test
+  public void testGroupByKeyIterator() {
+    GroupByKeyIterator<String, Integer, GlobalWindow> iteratorUnderTest = 
createGbkIterator();
+
+    Assert.assertTrue(iteratorUnderTest.hasNext());
+    WindowedValue<KV<String, Iterable<Integer>>> k1Win = 
iteratorUnderTest.next();
+    // testing that calling 2x hasNext doesn't move to next key iterator
+    Assert.assertTrue(iteratorUnderTest.hasNext());
+    Assert.assertTrue(iteratorUnderTest.hasNext());
+
+    Iterator<Integer> valuesIteratorForK1 = 
k1Win.getValue().getValue().iterator();
+
+    Assert.assertTrue("Now we expect first value for K1 to pop up.", 
valuesIteratorForK1.hasNext());
+    assertEquals(1L, valuesIteratorForK1.next().longValue());
+    Assert.assertTrue(valuesIteratorForK1.hasNext());
+    Assert.assertTrue(valuesIteratorForK1.hasNext());
+    assertEquals(2L, valuesIteratorForK1.next().longValue());
+
+    WindowedValue<KV<String, Iterable<Integer>>> k2Win = 
iteratorUnderTest.next();
+    Iterator<Integer> valuesIteratorForK2 = 
k2Win.getValue().getValue().iterator();
+    assertEquals(3L, valuesIteratorForK2.next().longValue());
+  }
+
+  @Test(expected = IllegalStateException.class)
+  public void testGbkIteratorValuesCannotBeReiterated() {
+    GroupByKeyIterator<String, Integer, GlobalWindow> iteratorUnderTest = 
createGbkIterator();
+    WindowedValue<KV<String, Iterable<Integer>>> firstEl = 
iteratorUnderTest.next();
+    Iterable<Integer> value = firstEl.getValue().getValue();
+    for (Integer i : value) {
 
 Review comment:
   I wonder if there is a cleaner way to do this so static analysis tools do 
not complain about the empt[y loop and unused variable, but I could not find 
quickly and alternative.
 
----------------------------------------------------------------
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:
[email protected]


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

    Worklog Id:     (was: 195595)
    Time Spent: 1.5h  (was: 1h 20m)

> GroupByKey on Spark: All values for a single key need to fit in-memory at once
> ------------------------------------------------------------------------------
>
>                 Key: BEAM-5392
>                 URL: https://issues.apache.org/jira/browse/BEAM-5392
>             Project: Beam
>          Issue Type: Bug
>          Components: runner-spark
>    Affects Versions: 2.6.0
>            Reporter: David Moravek
>            Assignee: David Moravek
>            Priority: Major
>              Labels: performance, triaged
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> Currently, when using GroupByKey, all values for a single key need to fit 
> in-memory at once.
>  
> There are following issues, that need to be addressed:
> a) We can not use Spark's _groupByKey_, because it requires all values to fit 
> in memory for a single key (it is implemented as "list combiner")
> b) _ReduceFnRunner_ iterates over values multiple times in order to group 
> also by window
>  
> Solution:
>  
> In Dataflow Worker code, there are optimized versions of ReduceFnRunner, that 
> can take advantage of having elements for a single key sorted by timestamp.
>  
> We can use Spark's `{{repartitionAndSortWithinPartitions}}` in order to meet 
> this constraint.
>  
> For non-merging windows, we can put window itself into the key resulting in 
> smaller groupings.
>  
> This approach was already tested in ~100TB input scale on Spark 2.3.x. 
> (custom Spark runner).
>  
> I'll submit a patch once the Dataflow Worker code donation is complete.



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

Reply via email to