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/08/04 21:19:33 UTC

[GitHub] [beam] pabloem commented on a change in pull request #15242: Refactor _RemoveDuplicates to use counter state

pabloem commented on a change in pull request #15242:
URL: https://github.com/apache/beam/pull/15242#discussion_r682967218



##########
File path: sdks/python/apache_beam/io/fileio.py
##########
@@ -804,16 +803,17 @@ def finish_bundle(self):
 
 class _RemoveDuplicates(beam.DoFn):
 
-  FILES_STATE = BagStateSpec('files', StrUtf8Coder())
+  COUNT_STATE = CombiningValueStateSpec('count', combine_fn=sum)
+
+  def process(self, element, count_state=beam.DoFn.StateParam(COUNT_STATE)):
 
-  def process(self, element, file_state=beam.DoFn.StateParam(FILES_STATE)):
     path = element[0]
     file_metadata = element[1]
-    bag_content = [x for x in file_state.read()]
+    counter = count_state.read()
 
-    if not bag_content:
-      file_state.add(path)
+    if counter == 0:
+      count_state.add(1)
       _LOGGER.debug('Generated entry for file %s', path)
       yield file_metadata
     else:
-      _LOGGER.debug('File %s was already read', path)
+      _LOGGER.debug("File %s was already read", path)

Review comment:
       Maybe log the number of times it's been seen before?
   LGTM otherwise.




-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org