Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.

We should put this in the samples directory like

{{< code_sample "sdks/python/apache_beam/examples/snippets/snippets.py" SideInputSlowUpdateSnip1 >}}

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.

It should also have associated tests

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

We should use a streaming source here - I'd recommend trying to replicate

public static class PeriodicallyUpdatingSideInputs {

)

side_input = (
p
| "GenerateSignal" >> beam.Create([None])
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.

Same thing here, this should be a streaming source like

public static class PeriodicallyUpdatingSideInputs {

| "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 >}}


Expand Down