From f40792db3b1ed7e5d1ea9c8b2d26da62f5ddb9f3 Mon Sep 17 00:00:00 2001 From: Ahmet Altay Date: Tue, 20 Jun 2017 14:25:55 -0700 Subject: [PATCH] Add a cloud-pubsub dependency to the list of gcp extra packages --- .../apache_beam/examples/streaming_wordcount.py | 13 ++++++++----- sdks/python/setup.py | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sdks/python/apache_beam/examples/streaming_wordcount.py b/sdks/python/apache_beam/examples/streaming_wordcount.py index ed8b5d08dc62e..f2b179aa2438d 100644 --- a/sdks/python/apache_beam/examples/streaming_wordcount.py +++ b/sdks/python/apache_beam/examples/streaming_wordcount.py @@ -25,16 +25,19 @@ import argparse import logging -import re import apache_beam as beam import apache_beam.transforms.window as window +def split_fn(lines): + import re + return re.findall(r'[A-Za-z\']+', x) + + def run(argv=None): """Build and run the pipeline.""" - parser = argparse.ArgumentParser() parser.add_argument( '--input_topic', required=True, @@ -46,14 +49,14 @@ def run(argv=None): with beam.Pipeline(argv=pipeline_args) as p: - # Read the text file[pattern] into a PCollection. + # Read from PubSub into a PCollection. lines = p | beam.io.ReadStringsFromPubSub(known_args.input_topic) # Capitalize the characters in each line. transformed = (lines + # Use a pre-defined function that imports the re package. | 'Split' >> ( - beam.FlatMap(lambda x: re.findall(r'[A-Za-z\']+', x)) - .with_output_types(unicode)) + beam.FlatMap(split_fn).with_output_types(unicode)) | 'PairWithOne' >> beam.Map(lambda x: (x, 1)) | beam.WindowInto(window.FixedWindows(15, 0)) | 'Group' >> beam.GroupByKey() diff --git a/sdks/python/setup.py b/sdks/python/setup.py index 051043b07e7f5..584c852c57b82 100644 --- a/sdks/python/setup.py +++ b/sdks/python/setup.py @@ -118,6 +118,7 @@ def get_version(): 'google-apitools>=0.5.10,<=0.5.11', 'proto-google-cloud-datastore-v1>=0.90.0,<=0.90.4', 'googledatastore==7.0.1', + 'google-cloud-pubsub==0.25.0', # GCP packages required by tests 'google-cloud-bigquery>=0.23.0,<0.25.0', ]