boyuanzz commented on a change in pull request #14182:
URL: https://github.com/apache/beam/pull/14182#discussion_r591916291



##########
File path: 
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/WindowMergingFnRunner.java
##########
@@ -151,10 +151,12 @@ public void merge(Collection<W> toBeMerged, W 
mergeResult) throws Exception {
         KV<T, Iterable<W>> windowsToMerge) throws Exception {
       currentWindows = Sets.newHashSet(windowsToMerge.getValue());
       windowFn.mergeWindows((MergeContext) mergeContext);

Review comment:
       We can do `mergedWindows.clear();` before we invoke 
`windowFn.mergeWindows` instead of making a copy, right?

##########
File path: 
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/WindowMergingFnRunner.java
##########
@@ -151,10 +151,12 @@ public void merge(Collection<W> toBeMerged, W 
mergeResult) throws Exception {
         KV<T, Iterable<W>> windowsToMerge) throws Exception {
       currentWindows = Sets.newHashSet(windowsToMerge.getValue());
       windowFn.mergeWindows((MergeContext) mergeContext);
+      ArrayList mergedWindowsCopy = new ArrayList<>(mergedWindows);
       for (KV<W, Collection<W>> mergedWindow : mergedWindows) {
         currentWindows.removeAll(mergedWindow.getValue());
       }
-      return KV.of(windowsToMerge.getKey(), KV.of(currentWindows, (Iterable) 
mergedWindows));
+      mergedWindows.clear();

Review comment:
       It seems like it's a bug which can result in wrong results before this 
change, right? If it's not too complicated, can we add a unit test like 
FnApiDoFnRunnerTest to guard this cleanup logic?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to