You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/06/02 06:23:07 UTC

[GitHub] [beam] hoshimura commented on a change in pull request #14916: [BEAM-12434] Implement side_input for num_shards in iobase

hoshimura commented on a change in pull request #14916:
URL: https://github.com/apache/beam/pull/14916#discussion_r643684460



##########
File path: sdks/python/apache_beam/io/iobase.py
##########
@@ -1226,17 +1226,13 @@ def _finalize_write(
 
 
 class _RoundRobinKeyFn(core.DoFn):
-  def __init__(self, count):
-    # type: (int) -> None
-    self.count = count
-
   def start_bundle(self):
-    self.counter = random.randint(0, self.count - 1)
+    self.counter = random.random()
 
-  def process(self, element):
-    self.counter += 1
-    if self.counter >= self.count:
-      self.counter -= self.count
+  def process(self, element, count):
+    if self.counter < 1:

Review comment:
       That is true, however either self.counter will either be a value in the semi-closed interval [0,1) or zero so the effect of the if statement may only be non-zero after the first start_bundle. Coding wise your suggestion is probably cleaner.




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