-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add Python example for slowly updating global window side input pattern #37789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -48,7 +48,40 @@ For instance, the following code sample uses a `Map` to create a `DoFn`. The `Ma | |||
| {{< /highlight >}} | ||||
|
|
||||
| {{< highlight py >}} | ||||
| No sample present. | ||||
| import apache_beam as beam | ||||
| from apache_beam.options.pipeline_options import PipelineOptions | ||||
|
|
||||
| class FetchSideInput(beam.DoFn): | ||||
| def process(self, element): | ||||
| # simulate fetching external data | ||||
| yield {"threshold": 10} | ||||
|
|
||||
| def run(): | ||||
| with beam.Pipeline(options=PipelineOptions()) as p: | ||||
|
|
||||
| main_input = ( | ||||
| p | ||||
| | "CreateMainInput" >> beam.Create([1, 5, 10, 20]) | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use a streaming source here - I'd recommend trying to replicate beam/examples/java/src/main/java/org/apache/beam/examples/snippets/Snippets.java Line 888 in 180f3a6
|
||||
| ) | ||||
|
|
||||
| side_input = ( | ||||
| p | ||||
| | "GenerateSignal" >> beam.Create([None]) | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here, this should be a streaming source like beam/examples/java/src/main/java/org/apache/beam/examples/snippets/Snippets.java Line 888 in 180f3a6
|
||||
| | "FetchSideInput" >> beam.ParDo(FetchSideInput()) | ||||
| | beam.combiners.Latest.Globally().without_defaults() | ||||
| ) | ||||
|
|
||||
| result = ( | ||||
| main_input | ||||
| | "ApplySideInput" >> beam.Map( | ||||
| lambda x, s: x > s["threshold"], | ||||
| beam.pvalue.AsSingleton(side_input)) | ||||
| ) | ||||
|
|
||||
| result | beam.Map(print) | ||||
|
|
||||
| if __name__ == "__main__": | ||||
| run() | ||||
| {{< /highlight >}} | ||||
|
|
||||
|
|
||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should put this in the samples directory like
beam/website/www/site/content/en/documentation/patterns/side-inputs.md
Line 79 in 180f3a6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should also have associated tests