-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_beam.py
52 lines (42 loc) · 1.4 KB
/
hello_beam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
"""
hello_beam.py
Sample file for running a very simple pipeline in Apache Beam locally.
Takes a file as input and saves a file as output.
Usage:
python hello_beam.py
--input PATH_TO_INPUT_FILE
--output PATH_TO_OUTPUT_FILE
"""
import argparse
import logging
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.options.pipeline_options import SetupOptions
from apache_beam.options.pipeline_options import StandardOptions
def run(argv=None):
"""Build and run the pipeline."""
parser = argparse.ArgumentParser()
parser.add_argument(
'--input',
dest='input',
default='data/input/us-500.csv',
help='Input file to process')
parser.add_argument(
'--output',
dest='output',
default='data/output/hello_beam/hello_beam',
help='Output local filename')
args, pipeline_args = parser.parse_known_args(argv)
options = PipelineOptions(pipeline_args)
options.view_as(SetupOptions).save_main_session = True
options.view_as(StandardOptions).streaming = False
p = beam.Pipeline(options=options)
(p | 'Read from Input File' >> beam.io.ReadFromText(args.input)
| 'Write to file' >> beam.io.WriteToText(args.output)
)
result = p.run()
result.wait_until_finish()
if __name__ == "__main__":
logging.getLogger().setLevel(logging.INFO)
run()