Repository navigation
Description
What happened?
In batch, iobase.Write (which backs WriteToText, WriteToAvro, WriteToParquet and WriteToTFRecord) returns a PCollection of the final file paths. Each path is emitted in the GlobalWindow with timestamp MAX_TIMESTAMP (iobase.py#L1476). That's past the end of the global window, since GlobalWindow().max_timestamp() is MAX_TIMESTAMP minus one day, so downstream aggregations treat the paths as data beyond their window's end:
- Prism (the default local runner): a
GroupByKeyon the paths fails the job withpanic in ElementManager.Bundles watermark evaluation goroutine: generating bundle for stage stage-009 at watermark +inf panicked.
assert_that(paths, equal_to([...]))sees an emptyPCollectionand the job fails withnothing in progress and no refreshes with non zero pending elements: 3. - BundleBasedDirectRunner:
beam.combiners.Count.Globally()on the paths returns0instead of3. - FnApiRunner: works.
Repro on master (1cabbd7), Python 3.13:
import tempfile
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
tmp = tempfile.mkdtemp()
with beam.Pipeline(options=PipelineOptions(['--runner=PrismRunner'])) as p:
paths = p | beam.Create(['a', 'b', 'c']) | beam.io.WriteToText(
tmp + '/out', num_shards=3)
_ = paths | beam.Map(lambda x: (0, x)) | beam.GroupByKey() | beam.Map(print)The default num_shards=0 fails the same way. With --runner=BundleBasedDirectRunner, paths | beam.combiners.Count.Globally() | beam.Map(print) prints 0.
Cause. BEAM-5250 (7581caa, 2018) changed _WriteBundleDoFn to emit at GlobalWindow().max_timestamp() (L1346). Two places still use timestamp.MAX_TIMESTAMP:
_finalize_write(L1476), which produces the transform's output._WriteKeyedBundleDoFn(L1449), whose results are only read as a side input.
Possible fix. Emit at window.GlobalWindow().max_timestamp() in _finalize_write, and in _WriteKeyedBundleDoFn for consistency. I tried the _finalize_write change locally: the repro then works on all three runners (GroupByKey succeeds on Prism, and Count.Globally() returns 3 on Prism and on BundleBasedDirectRunner).
Streaming writes go through _finalize_windowed_write instead and aren't covered by this report. Separately, Prism panicking on these elements, rather than handling them as late data, may be worth a look by its maintainers.
I found this while working on #25769, which documents this output. A test that asserts on the output can't pass on Prism without this fix, so I plan to include the fix in that PR.
Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
Issue Components
- Component: Python SDK
- Component: Java SDK
- Component: Go SDK
- Component: Typescript SDK
- Component: IO connector
- Component: Beam YAML
- Component: Beam examples
- Component: Beam playground
- Component: Beam katas
- Component: Website
- Component: Infrastructure
- Component: Spark Runner
- Component: Flink Runner
- Component: Prism Runner
- Component: Hazelcast Jet Runner
- Component: Google Cloud Dataflow Runner
Activity
jonathansudhakar1 commentedon Nov 12, 2026
.add-labels bug,'awaiting triage'
[Python] Emit Write's output file paths at the end of the global window
[Python] Emit Write's output file paths at the end of the global window
[Python] Emit Write's output file paths at the end of the global window
Address review comments: move the batch output-path test to the apach…
jonathansudhakar1 commentedon Nov 28, 2026
.take-issue
The fix is now in its own PR, #41738 (split out of #41318, which keeps the docs for #25769).