Skip to content

Add Python example for slowly updating global window side inputs - #40183

Merged
chamikaramj merged 2 commits into
apache:masterfrom
ashwin-sampathkumar:python-slow-update-global-window-side-input
Sep 21, 2026
Merged

chamikaramj merged 2 commits into
apache:masterfrom
ashwin-sampathkumar:python-slow-update-global-window-side-input

Conversation

@ashwin-sampathkumar

Copy link
Copy Markdown
Contributor

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:

  • Mention the appropriate issue in your description (for example: 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, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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)

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.

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
@github-actions

Copy link
Copy Markdown
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

@chamikaramj chamikaramj 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.

Thanks!

from apache_beam.transforms import window
from apache_beam.transforms.periodicsequence import PeriodicImpulse

# from apache_beam.utils.timestamp import MAX_TIMESTAMP

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.

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

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.

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

@chamikaramj chamikaramj Sep 18, 2026 •

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.

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

I can merge when comments are resolved. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm for label python.
R: @Abacn for label website.

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

- 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.
@chamikaramj
chamikaramj merged commit 7143520 into apache:master Sep 21, 2026
103 checks passed
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.

2 participants