Skip to content

[Python] Document the file paths output by file-based sinks - #41318

Open
jonathansudhakar1 wants to merge 4 commits into
apache:masterfrom
jonathansudhakar1:docs-filesink-paths-25769
Open

jonathansudhakar1 wants to merge 4 commits into
apache:masterfrom
jonathansudhakar1:docs-filesink-paths-25769

Conversation

@jonathansudhakar1

@jonathansudhakar1 jonathansudhakar1 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25769

The fix for #41245 that used to be part of this PR is now its own PR, #41738, as requested in review. This PR is docs only, plus one streaming test.

What

  • FileBasedSink (filebasedsink.py), the base class of the sinks behind WriteToText, WriteToAvro, WriteToParquet, WriteToParquetBatched and WriteToTFRecord, already said its output is "a PCollection of all written shards". Its docstring now describes that output in full: a PCollection of str holding the final path of each file written, one per shard, emitted once that file is in place. For windowed writes (for example streaming with triggering_frequency), each window's paths are emitted after that window is finalized.
    It also notes the retry caveat raised in the issue thread: a finalization retry doesn't re-emit files that an earlier attempt already renamed, so the output may not list every file. I went ahead with option (1) from my comment on [Feature Request]: Document that file-based sinks return a PCollection of output filenames #25769 (document the caveat and leave any behavior change for a separate PR), since there was no reply after 5 business days.
  • The five transforms now say in one sentence that their output is a PCollection of the final paths of the files written, and refer to FileBasedSink for the details, so the explanation lives in one place.
  • iobase.Write's docstring said it returned "a pvalue.PValue object that represents the end of the Pipeline". It now describes the actual output and refers to FileBasedSink for file-based sinks. Sink.finalize_write() documents its return value.
  • Test: WriteStreamingTest.test_write_streaming_outputs_final_file_paths checks that a windowed WriteToText (TestStream, triggering_frequency=10) outputs exactly the paths of the files it wrote. It passes without [Python] Emit Write's output file paths at the end of the global window #41738, because windowed writes already emit their paths inside their window. The batch counterpart moved to [Python] Emit Write's output file paths at the end of the global window #41738, since it needs that fix to pass on Prism.

Testing (Python 3.13, macOS, at 719d6aa on 1c20e38)

  • pytest apache_beam/io/textio_test.py -k test_write_streaming_outputs_final_file_paths: 1 passed.
  • pytest -n 6 on apache_beam/io/{textio,filebasedsink,iobase,avroio,parquetio,tfrecordio}_test.py and apache_beam/transforms/write_ptransform_test.py: 266 passed, 10 skipped.
  • pre-commit run --files <changed files> (yapf, ruff): passed. pylint --rcfile=.pylintrc on the changed .py files: 10.00/10.
  • I didn't build the Sphinx docs locally (Sphinx isn't installed here), so the docs precommit is the check for the new :class: references. Windows isn't available locally; the earlier Windows failure was fixed in 1b91967 (os.path.join).

@github-actions github-actions Bot added python io size/m M: 50-249 lines changed labels Nov 13, 2026

@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 fixes the batch output timestamps of iobase.Write (_finalize_write and _WriteKeyedBundleDoFn) to use GlobalWindow().max_timestamp() instead of timestamp.MAX_TIMESTAMP, preventing downstream grouping failures in Prism and dropped elements in BundleBasedDirectRunner (#41245). It also clearly documents the output PCollection of finalized file paths (along with windowed behavior and finalization retry semantics) across iobase.Write, Sink.finalize_write, and the file-based sink transforms (#25769).

🔍 General Feedback

  • Aligning _finalize_write and _WriteKeyedBundleDoFn with _WriteBundleDoFn.finish_bundle() (window.GlobalWindow().max_timestamp()) is clean and ensures emitted elements remain within the bounds of GlobalWindow.
  • The added unit tests in textio_test.py thoroughly cover batch file path outputs, output timestamps for both num_shards=0 and num_shards=3, and streaming windowed file path outputs.

💡 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: @shunping for label python.
Backup reviewer: damccorm (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).

@github-actions
github-actions Bot requested a review from shunping November 13, 2026 19:08
@jonathansudhakar1
jonathansudhakar1 force-pushed the docs-filesink-paths-25769 branch 2 times, most recently from a2de4de to e55f824 Compare November 18, 2026 17:03
@jonathansudhakar1

Copy link
Copy Markdown
Contributor Author

@shunping a gentle ping when you have a moment: this fixes #41245 (file-based sinks emit their output file paths at MAX_TIMESTAMP, past the end of the global window) and documents what those sinks output (#25769). I rebased it onto current master today for a CHANGES.md conflict, and the IO tests still pass locally (266 passed, 10 skipped). I'm happy to split the fix and the docs into two PRs if that's easier to review. Thanks!

@jonathansudhakar1
jonathansudhakar1 force-pushed the docs-filesink-paths-25769 branch from e55f824 to b84907d Compare November 20, 2026 17:04
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.43%. Comparing base (5d834f2) to head (ce693c9).
⚠️ Report is 107 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41318      +/-   ##
============================================
+ Coverage     59.38%   59.43%   +0.05%     
  Complexity     5137     5137              
============================================
  Files          1470     1470              
  Lines        187512   187748     +236     
  Branches       3819     3819              
============================================
+ Hits         111351   111596     +245     
+ Misses        72756    72747       -9     
  Partials       3405     3405              
Flag Coverage Δ
python 80.69% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shunping shunping left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The newly-added tests failed to run on windows. Please address that. Thanks!

shutil.rmtree(self.tempdir)

def test_write_streaming_outputs_final_file_paths(self):
prefix = self.tempdir + '/output'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The "/" is the culprit for the test failure on windows.

@jonathansudhakar1 jonathansudhakar1 Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, good catch. On Windows glob.glob joins the directory and file name with a backslash, so the expected paths built with '/' didn't match. ce693c9 builds the prefix with os.path.join(self.tempdir, 'output') instead, so the pipeline output, the expected list and the glob result all use the native separator. This was the only failure in the four Windows jobs (the same test each time). I can't run Windows locally; on macOS the three new tests pass, and the seven touched IO test modules give 268 passed, 10 skipped with the branch merged into current master.

@jonathansudhakar1

Copy link
Copy Markdown
Contributor Author

Thanks for the review! The Windows failure is fixed in ce693c9: the new streaming test now builds its output prefix with os.path.join (details in the review thread). It was the only test failing in the four Windows jobs. Ready for another look whenever you have time.

@shunping

Copy link
Copy Markdown
Collaborator

Thanks for the review! The Windows failure is fixed in ce693c9: the new streaming test now builds its output prefix with os.path.join (details in the review thread). It was the only test failing in the four Windows jobs. Ready for another look whenever you have time.

Rerunning tests now.

@shunping shunping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey @jonathansudhakar1, taking another look, the documentation changes seem orthogonal to the sink output timestamp fix. Could you please split them into two separate PRs?

For the documentation changes, instead of duplicating the text for different IOs, have you considered there a way to put the explanation in one class (like the base class) and refer to it in the derived ones?

Thanks again for working on this!

WriteToText, WriteToAvro, WriteToParquet, WriteToParquetBatched and
WriteToTFRecord return a PCollection of the final paths of the files they
write, but their docstrings didn't say so, and iobase.Write's docstring said
it returned a PValue marking the end of the pipeline.

Document the output in each transform, including that a finalization retry
doesn't re-emit files that an earlier attempt already renamed, and document
the return value of Sink.finalize_write(). Add batch and streaming tests that
check WriteToText's output against the files written.

Fixes apache#25769
…h os.path.join

On Windows, glob.glob returns paths joined with the native separator, so
the expected paths built with '/' didn't match the files that were found.
…e#41245 fix

The batch test asserts on WriteToText's output with assert_that, which
groups it, and that fails on Prism until the apache#41245 fix is in. Move it to
the PR for that fix, so that this PR doesn't depend on it. The streaming
test stays: windowed writes already emit their paths inside their window.
WriteToText, WriteToAvro, WriteToParquet, WriteToParquetBatched and
WriteToTFRecord repeated the same paragraph about their output. Describe it
once, in the docstring of FileBasedSink, the base class of the sinks behind
them, which already said that the output lists the shards written, and have
the transforms and iobase.Write refer to it.
@jonathansudhakar1
jonathansudhakar1 force-pushed the docs-filesink-paths-25769 branch from ce693c9 to 719d6aa Compare November 28, 2026 14:10
@jonathansudhakar1 jonathansudhakar1 changed the title [Python] Document and fix the file paths output by file-based sinks [Python] Document the file paths output by file-based sinks Nov 28, 2026
@github-actions github-actions Bot added core size/s S: 10-49 lines changed and removed size/m M: 50-249 lines changed labels Nov 28, 2026
@jonathansudhakar1

Copy link
Copy Markdown
Contributor Author

Thanks for taking another look! I've split it as you suggested:

For the docs, the explanation now lives in one place, the FileBasedSink class docstring. That's the base class of the sinks behind all five transforms, and it already had a one-line note about the output. WriteToText, WriteToAvro, WriteToParquet, WriteToParquetBatched and WriteToTFRecord each keep one sentence that refers to it, and so does iobase.Write (719d6aa). The two PRs don't overlap and merge cleanly together, so they can go in either order.

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.

[Feature Request]: Document that file-based sinks return a PCollection of output filenames

2 participants