Skip to content

[Python] Emit Write's output file paths at the end of the global window - #41738

Open
jonathansudhakar1 wants to merge 1 commit into
apache:masterfrom
jonathansudhakar1:write-output-timestamp-41245
Open

jonathansudhakar1 wants to merge 1 commit into
apache:masterfrom
jonathansudhakar1:write-output-timestamp-41245

Conversation

@jonathansudhakar1

Copy link
Copy Markdown
Contributor

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.Write emits the final file paths of file-based sinks such as WriteToText at MAX_TIMESTAMP, which is past the end of the global window. Grouping that output downstream fails the job on Prism, and Count.Globally() on it returns 0 on the BundleBasedDirectRunner (details in #41245).

The paths are now emitted at GlobalWindow().max_timestamp(), as _WriteBundleDoFn has 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 of WriteToText's output, with num_shards 0 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. With iobase.py reverted to master, both fail on the default test runner (Prism).
  • pytest -n 6 on apache_beam/io/{textio,filebasedsink,iobase,avroio,parquetio,tfrecordio}_test.py and apache_beam/transforms/write_ptransform_test.py: 267 passed, 10 skipped.
  • pre-commit run --files <changed files> (yapf, ruff): passed. pylint --rcfile=.pylintrc on the changed .py files: 10.00/10.
  • The repro from [Bug]: Python file-based sinks emit their output file paths at MAX_TIMESTAMP, past the end of the global window #41245 (WriteToText(..., num_shards=3), then GroupByKey and Count.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: from MAX_TIMESTAMP to the end of the global window, about a day earlier. Windowed writes (_finalize_windowed_write) aren't touched.

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 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_write and _WriteKeyedBundleDoFn aligns cleanly with the existing behavior of _WriteBundleDoFn.finish_bundle.
  • The unit tests in textio_test.py thoroughly cover both num_shards=0 and num_shards=3 code paths as well as downstream grouping via assert_that.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm for label python.
Backup reviewer: claudevdm (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Python file-based sinks emit their output file paths at MAX_TIMESTAMP, past the end of the global window

1 participant