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/01 21:04:56 UTC

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

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



##########
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:
       I believe this was written to initialize self.counter, but it will also be true every time `(1 + self.counter) % count` is zero. Instead, you could initialize `self.counter = None` in start_bundle and check for None on this line.




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