Skip to content

unbounded PCollections writes to files support in iobase derived IOs: AvroIO, ParquetIO , TextIO, TFRecordIO#34777

Closed
razvanculea wants to merge 24 commits intoapache:masterfrom
razvanculea:iobase
Closed

unbounded PCollections writes to files support in iobase derived IOs: AvroIO, ParquetIO , TextIO, TFRecordIO#34777
razvanculea wants to merge 24 commits intoapache:masterfrom
razvanculea:iobase

Conversation

@razvanculea
Copy link
Contributor

iobase patch for writing unbounded PColl sources.
Implement unbounded PCollections writes to files support in iobase derived IOs: AvroIO, ParquetIO , TextIO, TFRecordIO
Tests for streming PCollections writes to files in AvroIO, ParquetIO , TextIO, TFRecordIO


To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions
Copy link
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

Comment on lines +1168 to +1173
init_result_window_coll = (
keyed_pcoll
| core.WindowInto(window.GlobalWindows())
| core.GroupByKey()
| 'WriteBundles' >> core.ParDo(
_WriteKeyedBundleDoFn(self.sink), AsSingleton(init_result_coll)))
| 'Pair init' >> core.Map(lambda x: (None, x))
| 'Pair init gbk' >> core.GroupByKey()
| 'InitializeWindowedWrite' >> core.Map(
lambda _, sink: sink.initialize_write(), self.sink)
Copy link
Contributor

@sjvanrossum sjvanrossum Apr 29, 2025

Choose a reason for hiding this comment

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

This doesn't have to depend on the main input, right?

Comment on lines +1152 to +1159
if isinstance(pcoll.windowing.windowfn, window.GlobalWindows):
widowed_pcoll = (
pcoll
| core.WindowInto(window.FixedWindows(self.sink.triggering_frequency),
trigger=beam.transforms.trigger.AfterWatermark(),
accumulation_mode=beam.transforms.trigger.AccumulationMode.DISCARDING,
allowed_lateness=beam.utils.timestamp.Duration(seconds=0))
)
Copy link
Contributor

Choose a reason for hiding this comment

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

If the input is globally windowed a trigger within the global window set to repeat every sink.triggering_frequency would be what I'd expect instead of windowing into FixedWindows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that would be an alternative way to implement.
The windowing will help have elements of the same window in the same file, vs group into batches & trigger will have elements as they come (possibly mixed)

@github-actions
Copy link
Contributor

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

R: @shunping for label python.

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).

@liferoad
Copy link
Contributor

liferoad commented May 2, 2025

is this PR tested with DataflowRunner?

@razvanculea
Copy link
Contributor Author

is this PR tested with DataflowRunner?

@liferoad i've added the iobase_it_test from PR 34814 and it runs on Dataflow (it's actually using TextIO for write), but i don't have an IT for TextIO/parquetIO/AvroIO/TFRecordIO, I can try to add them, but i can't use TestStream in Dataflow, so i'll need to use PubSub public topics , right ?

@liferoad
Copy link
Contributor

liferoad commented May 5, 2025

is this PR tested with DataflowRunner?

@liferoad i've added the iobase_it_test from PR 34814 and it runs on Dataflow (it's actually using TextIO for write), but i don't have an IT for TextIO/parquetIO/AvroIO/TFRecordIO, I can try to add them, but i can't use TestStream in Dataflow, so i'll need to use PubSub public topics , right ?

is this PR tested with DataflowRunner?

@liferoad i've added the iobase_it_test from PR 34814 and it runs on Dataflow (it's actually using TextIO for write), but i don't have an IT for TextIO/parquetIO/AvroIO/TFRecordIO, I can try to add them, but i can't use TestStream in Dataflow, so i'll need to use PubSub public topics , right ?

I forgot whether periodic impulse can trigger #25598. You could try that. And better add some checks about the output results.

@razvanculea
Copy link
Contributor Author

is this PR tested with DataflowRunner?

@liferoad i've added the iobase_it_test from PR 34814 and it runs on Dataflow (it's actually using TextIO for write), but i don't have an IT for TextIO/parquetIO/AvroIO/TFRecordIO, I can try to add them, but i can't use TestStream in Dataflow, so i'll need to use PubSub public topics , right ?

is this PR tested with DataflowRunner?

@liferoad i've added the iobase_it_test from PR 34814 and it runs on Dataflow (it's actually using TextIO for write), but i don't have an IT for TextIO/parquetIO/AvroIO/TFRecordIO, I can try to add them, but i can't use TestStream in Dataflow, so i'll need to use PubSub public topics , right ?

I forgot whether periodic impulse can trigger #25598. You could try that. And better add some checks about the output results.

@liferoad, I added an IT in parquetio_it_test.py using PeriodicImpulse and it's working fine on Dataflow

Did not add IT for AvroIO/TFRecordIO because there is no IT at all. I could do like for parquetIO later, if we deem this really a plus.

@liferoad liferoad requested a review from shunping May 6, 2025 14:00
…requency param. On GlobalWindow throw an exception if trigger_frequency is not set / 0.
@razvanculea
Copy link
Contributor Author

razvanculea commented May 7, 2025

Improved support for user windowing.
If an unbounded PCollection with GlobalWindow is written:

  • without setting triggering_frequency => throw an exception
  • if triggering_frequency is set, then the output will be written per requested frequency

If an unbounded PCollection with a user set windowing is written:

  • without setting triggering_frequency => then the output will be written per user defined window
  • if triggering_frequency is set, then the output will be written per requested frequency (this overrides the user defined window)

If num_shards is set : per triggering_frequency/user window, the output is written in num_shards files
If num_shards is not set : per triggering_frequency/user window, the output is written with 1 file per bundle

@github-actions
Copy link
Contributor

Reminder, please take a look at this pr: @shunping

@github-actions
Copy link
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @jrmccluskey for label python.

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)

@shunping
Copy link
Collaborator

shunping commented May 20, 2025

@razvanculea, sorry about the delay of the review. Do you mind merging to the latest master so that the tests are re-triggered?

@shunping
Copy link
Collaborator

waiting on author

@razvanculea
Copy link
Contributor Author

@shunping don't review this anymore.
I'll break it into IObase+FileBasedSync PR, and 1 PR per IO (Parquet,Avro,TFRecord,Text)
As @sjvanrossum pointed out I could avoid breaking changes, in case there are any private developped IOs that currently work for batch. These would not work for streaming without changes, but would still work as before on batch with newer SDK.

@shunping
Copy link
Collaborator

sg! Feel free to tag me when they are ready.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2025

Reminder, please take a look at this pr: @jrmccluskey

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.

4 participants