Skip to content

Commit

Permalink
Update example in Tour of Beam (#28718)
Browse files Browse the repository at this point in the history
This example was mixing the with-statement style of doing pipelines with actually calling the run method. This changes the example to only use the with-statement, which is the most common style found in the documentation.
  • Loading branch information
iht authored Sep 28, 2023
1 parent 2b7df3b commit e6dcd37
Showing 1 changed file with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,13 @@ def main(argv=None, save_main_session=True):
pipeline_options.view_as(SetupOptions).save_main_session = save_main_session

with beam.Pipeline(options=pipeline_options) as p:

# Read the text file[pattern] into a PCollection.
lines = p | 'Read' >> ReadFromText(known_args.input) \
# Read the text file[pattern] into a PCollection.
lines = p | 'Read' >> ReadFromText(known_args.input) \
| beam.Filter(lambda line: line != "")

# Write the output using a "Write" transform that has side effects.
# pylint: disable=expression-not-assigned
output = lines | 'Write' >> WriteToText(known_args.output)


result = p.run()
result.wait_until_finish()

# Write the output using a "Write" transform that has side effects.
# pylint: disable=expression-not-assigned
output = lines | 'Write' >> WriteToText(known_args.output)


if __name__ == '__main__':
Expand Down

0 comments on commit e6dcd37

Please sign in to comment.