Repository navigation
[Python] Emit Write's output file paths at the end of the global window - #41738
jonathansudhakar1 wants to merge 1 commit into
Conversation
In batch, iobase.Write emitted the final file paths (and, internally, the keyed writer results) at MAX_TIMESTAMP, which is past the end of the global window. Grouping the paths downstream then failed the job on Prism, and Count.Globally() on them returned 0 on the BundleBasedDirectRunner. Emit them at GlobalWindow().max_timestamp(), as _WriteBundleDoFn has done since BEAM-5250. The tests check the timestamps of WriteToText's output, and that assert_that, which groups its input, sees the paths of the files written. Fixes apache#41245
There was a problem hiding this comment.
📋 Review Summary
This PR resolves #41245 by emitting output file paths from iobase._finalize_write and writer results from _WriteKeyedBundleDoFn at window.GlobalWindow().max_timestamp() instead of timestamp.MAX_TIMESTAMP. This prevents elements from having timestamps past the end of the global window, fixing downstream grouping failures on Prism and dropped elements on the BundleBasedDirectRunner.
🔍 General Feedback
- The timestamp change in
_finalize_writeand_WriteKeyedBundleDoFnaligns cleanly with the existing behavior of_WriteBundleDoFn.finish_bundle. - The unit tests in
textio_test.pythoroughly cover bothnum_shards=0andnum_shards=3code paths as well as downstream grouping viaassert_that.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @damccorm for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Fixes #41245
This is the fix half of #41318, split out at @shunping's request there. #41318 now holds only the docs for #25769.
What
In batch,
iobase.Writeemits the final file paths of file-based sinks such asWriteToTextatMAX_TIMESTAMP, which is past the end of the global window. Grouping that output downstream fails the job on Prism, andCount.Globally()on it returns 0 on the BundleBasedDirectRunner (details in #41245).The paths are now emitted at
GlobalWindow().max_timestamp(), as_WriteBundleDoFnhas done since BEAM-5250 (7581caa)._WriteKeyedBundleDoFn's internal results get the same change for consistency; they're only read as a side input.Tests (in
textio_test.py)test_write_pipeline_output_timestamps_in_global_window: the timestamps ofWriteToText's output, withnum_shards0 and 3.test_write_pipeline_outputs_final_file_paths:assert_that(which groups its input) sees the paths of the 3 files written. This test was in [Python] Document the file paths output by file-based sinks #41318; it moved here because it needs the fix.Testing (Python 3.13, macOS, at dc9ba26 on 1c20e38)
pytest apache_beam/io/textio_test.py -k 'outputs_final_file_paths or output_timestamps_in_global_window': 2 passed. Withiobase.pyreverted to master, both fail on the default test runner (Prism).pytest -n 6onapache_beam/io/{textio,filebasedsink,iobase,avroio,parquetio,tfrecordio}_test.pyandapache_beam/transforms/write_ptransform_test.py: 267 passed, 10 skipped.pre-commit run --files <changed files>(yapf, ruff): passed.pylint --rcfile=.pylintrcon the changed.pyfiles: 10.00/10.WriteToText(..., num_shards=3), thenGroupByKeyandCount.Globally()on its output) on PrismRunner, BundleBasedDirectRunner and FnApiRunner: all three put the 3 paths in one group and count 3. On master, Prism panics in watermark evaluation, the BundleBasedDirectRunner counts 0, and FnApiRunner already works.Risk. Only the timestamp of
Write's batch output, and of its internal keyed-writer results, changes: fromMAX_TIMESTAMPto the end of the global window, about a day earlier. Windowed writes (_finalize_windowed_write) aren't touched.