Repository navigation
Add Python example for slowly updating global window side inputs - #40183
chamikaramj merged 2 commits into
Conversation
The "Slowly updating global window side inputs" section of the side input patterns page only had a Java sample; the Python block said "No sample present.". This adds a Python counterpart to the Java sample in snippets.py, references it from the website with code_sample, and covers it with a unit test. The example uses PeriodicImpulse as a streaming source, re-publishes the external data into the global window on every firing with a repeated trigger and discarding panes, and reads the value with Latest.Globally().without_defaults(). The without_defaults() variant is required because the default variant adds its own side input, which stops the transform from emitting more than once (apache#35934). Addresses apache#35935
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
| from apache_beam.transforms import window | ||
| from apache_beam.transforms.periodicsequence import PeriodicImpulse | ||
|
|
||
| # from apache_beam.utils.timestamp import MAX_TIMESTAMP |
There was a problem hiding this comment.
Nit: pls remove commented out code.
| for i in range(-1, 10, 1): | ||
| os.unlink(src_file_pattern + str(first_ts + interval * i)) | ||
|
|
||
| def test_side_input_slow_update_global_window(self): |
There was a problem hiding this comment.
Did we try the pipeline on Dataflow ? According to #35934 the behavior seems to be different for Dataflow.
| (expected_main_input_elements, main_input_elements)) | ||
|
|
||
| side_input_values = set(value for _, value in actual) | ||
| assert side_input_values, 'No side input value was observed.' |
There was a problem hiding this comment.
This assertion might be passing trivially for (main input, side input) combinations (<valid value>, None). Try changing to:
side_input_values = set(value for _, value in actual)
assert None not in side_input_values, (
'Some elements were processed before the side input was ready.')
chamikaramj
left a comment
There was a problem hiding this comment.
I can merge when comments are resolved. Thanks!
|
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). |
- Remove the commented-out code from the snippet, keeping the guidance about running indefinitely as a plain comment. - Fail the test when an element is processed before the side input is ready, instead of accepting a None side input value.
The "Slowly updating global window side inputs" section of the side input patterns page only had a Java sample; the Python block said "No sample present.".
This adds a Python counterpart to the Java sample in snippets.py, references it from the website with code_sample, and covers it with a unit test.
The example uses PeriodicImpulse as a streaming source, re-publishes the external data into the global window on every firing with a repeated trigger and discarding panes, and reads the value with
Latest.Globally().without_defaults(). The without_defaults() variant is required because the default variant adds its own side input, which stops the transform from emitting more than once (#35934).
Addresses #35935
Please add a meaningful description for your change here
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
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)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.