shunping commented on code in PR #35137: URL: https://github.com/apache/beam/pull/35137#discussion_r2143792817
########## sdks/python/apache_beam/io/iobase.py: ########## @@ -1127,47 +1168,183 @@ def __init__(self, sink: Sink) -> None: self.sink = sink def expand(self, pcoll): Review Comment: Here is a refactoring idea: ```python def _apply_windowing(self, pcoll): ... def _expand_bounded(self, pcoll, min_shards): """Handles the expansion logic for a bounded PCollection.""" do_once = pcoll.pipeline | 'DoOnce' >> core.Create([None]) init_result_coll = do_once | 'InitializeWrite' >> core.Map( lambda _, sink: sink.initialize_write(), self.sink) if min_shards > 1: ... else: # min_shards is 1 ... pre_finalize_coll = ( do_once | 'PreFinalize' >> core.FlatMap( _pre_finalize, self.sink, AsSingleton(init_result_coll), AsIter(write_result_coll))) return ( do_once | 'FinalizeWrite' >> core.FlatMap( _finalize_write, self.sink, AsSingleton(init_result_coll), AsIter(write_result_coll), min_shards, AsSingleton(pre_finalize_coll)).with_output_types(str) ) def _expand_unbounded(self, pcoll, min_shards): """Handles the expansion logic for an unbounded PCollection.""" windowed_pcoll = self._apply_windowing(pcoll) ... def expand(self, pcoll): min_shards = getattr(self.sink, 'num_shards', 0) or 1 if pcoll.is_bounded: return self._expand_bounded(pcoll, min_shards) else: return self._expand_unbounded(pcoll, min_shards) ``` -- 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-unsubscr...@beam.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org