damccorm commented on code in PR #41176:
URL: https://github.com/apache/beam/pull/41176#discussion_r4540467543


##########
sdks/python/apache_beam/runners/worker/operations.py:
##########
@@ -1224,17 +1222,32 @@ def finish(self):
 
   def flush(self, target):
     # type: (int) -> None
-    limit = self.size - target
-    for ix, (kw, vs) in enumerate(list(self.table.items())):
-      if ix >= limit:
+    if target <= 0:
+      for (key, windows), vs in self.table.items():
+        self.output(
+            windowed_value_create((key, [v.value[1] for v in vs]),
+                                  vs[0].timestamp_micros,
+                                  windows,
+                                  vs[0].pane_info))
+      self.table.clear()
+      self.size = 0
+      return
+
+    keys_to_delete = []
+    for kw, vs in self.table.items():
+      if self.size <= target:
         break
-      del self.table[kw]
+      keys_to_delete.append(kw)
+      self.size -= len(vs)
       key, windows = kw
       output_value = [v.value[1] for v in vs]
-      windowed_value = WindowedValue((key, output_value),
-                                     vs[0].timestamp,
-                                     windows)
+      windowed_value = windowed_value_create((key, output_value),
+                                             vs[0].timestamp_micros,
+                                             windows,
+                                             vs[0].pane_info)
       self.output(windowed_value)
+    for kw in keys_to_delete:
+      del self.table[kw]

Review Comment:
   (now deferred because we're iterating over the dict instead of 
`enumerate(list(self.table.items()))`, so deletion would break the iteration)



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to