You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by ro...@apache.org on 2017/01/03 19:28:22 UTC

[1/2] beam git commit: Update README examples to use the new io APIs

Repository: beam
Updated Branches:
  refs/heads/python-sdk 020daa96c -> 2df3eda4d


Update README examples to use the new io APIs


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/e6b9bbc5
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/e6b9bbc5
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/e6b9bbc5

Branch: refs/heads/python-sdk
Commit: e6b9bbc50a179abb5c184a47b8a4e9bd7279a367
Parents: 020daa9
Author: Maria Garcia Herrero <ma...@google.com>
Authored: Mon Jan 2 15:46:03 2017 -0800
Committer: Robert Bradshaw <ro...@google.com>
Committed: Tue Jan 3 11:28:07 2017 -0800

----------------------------------------------------------------------
 sdks/python/README.md | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/e6b9bbc5/sdks/python/README.md
----------------------------------------------------------------------
diff --git a/sdks/python/README.md b/sdks/python/README.md
index af0fb5e..42cbace 100644
--- a/sdks/python/README.md
+++ b/sdks/python/README.md
@@ -175,7 +175,7 @@ p = beam.Pipeline('DirectRunner')
 # Create a PCollection with names and write it to a file.
 (p
  | 'add names' >> beam.Create(['Ann', 'Joe'])
- | 'save' >> beam.io.Write(beam.io.TextFileSink('./names')))
+ | 'save' >> beam.io.WriteToText('./names'))
 # Execute the pipeline.
 p.run()
 ```
@@ -189,9 +189,9 @@ import apache_beam as beam
 p = beam.Pipeline('DirectRunner')
 # Read a file containing names, add a greeting to each name, and write to a file.
 (p
- | 'load names' >> beam.Read(beam.io.TextFileSource('./names'))
+ | 'load names' >> beam.io.ReadFromText('./names')
  | 'add greeting' >> beam.Map(lambda name, msg: '%s, %s!' % (msg, name), 'Hello')
- | 'save' >> beam.Write(beam.io.TextFileSink('./greetings')))
+ | 'save' >> beam.io.WriteToText('./greetings'))
 p.run()
 ```
 
@@ -207,11 +207,11 @@ import apache_beam as beam
 p = beam.Pipeline('DirectRunner')
 # Read a file containing names, add two greetings to each name, and write to a file.
 (p
- | 'load names' >> beam.Read(beam.io.TextFileSource('./names'))
+ | 'load names' >> beam.io.ReadFromText('./names')
  | 'add greetings' >> beam.FlatMap(
     lambda name, messages: ['%s %s!' % (msg, name) for msg in messages],
     ['Hello', 'Hola'])
- | 'save' >> beam.Write(beam.io.TextFileSink('./greetings')))
+ | 'save' >> beam.io.WriteToText('./greetings'))
 p.run()
 ```
 
@@ -230,9 +230,9 @@ def add_greetings(name, messages):
     yield '%s %s!' % (msg, name)
 
 (p
- | 'load names' >> beam.Read(beam.io.TextFileSource('./names'))
+ | 'load names' >> beam.io.ReadFromText('./names')
  | 'add greetings' >> beam.FlatMap(add_greetings, ['Hello', 'Hola'])
- | 'save' >> beam.Write(beam.io.TextFileSink('./greetings')))
+ | 'save' >> beam.io.WriteToText('./greetings'))
 p.run()
 ```
 
@@ -245,11 +245,10 @@ import re
 import apache_beam as beam
 p = beam.Pipeline('DirectRunner')
 (p
- | 'read' >> beam.Read(
-    beam.io.TextFileSource('gs://dataflow-samples/shakespeare/kinglear.txt'))
+ | 'read' >> beam.io.ReadFromText('gs://dataflow-samples/shakespeare/kinglear.txt')
  | 'split' >> beam.FlatMap(lambda x: re.findall(r'\w+', x))
  | 'count words' >> beam.combiners.Count.PerElement()
- | 'save' >> beam.Write(beam.io.TextFileSink('./word_count')))
+ | 'save' >> beam.io.WriteToText('./word_count'))
 p.run()
 ```
 
@@ -271,10 +270,10 @@ class MyCountTransform(beam.PTransform):
             | 'count words' >> beam.Map(lambda (word, counts): (word, len(counts))))
 
 (p
- | 'read' >> beam.Read(beam.io.TextFileSource('./names*'))
+ | 'read' >> beam.io.ReadFromText('./names*')
  | 'split' >> beam.FlatMap(lambda x: re.findall(r'\w+', x))
  | MyCountTransform()
- | 'write' >> beam.Write(beam.io.TextFileSink('./word_count')))
+ | 'write' >> beam.io.WriteToText('./word_count'))
 p.run()
 ```
 
@@ -288,10 +287,10 @@ import apache_beam as beam
 from apache_beam.typehints import typehints
 p = beam.Pipeline('DirectRunner')
 (p
- | 'read' >> beam.Read(beam.io.TextFileSource('./names'))
+ | 'read' >> beam.io.ReadFromText('./names')
  | 'add types' >> beam.Map(lambda x: (x, 1)).with_output_types(typehints.KV[str, int])
  | 'group words' >> beam.GroupByKey()
- | 'save' >> beam.Write(beam.io.TextFileSink('./typed_names')))
+ | 'save' >> beam.io.WriteToText('./typed_names'))
 p.run()
 ```
 
@@ -354,7 +353,7 @@ SAMPLE_DATA = [('a', 1), ('b', 10), ('a', 2), ('a', 3), ('b', 20)]
 (p
  | beam.Create(SAMPLE_DATA)
  | beam.CombinePerKey(sum)
- | beam.Write(beam.io.TextFileSink('./sums')))
+ | beam.io.WriteToText('./sums'))
 p.run()
 ```
 


[2/2] beam git commit: Closes #1726

Posted by ro...@apache.org.
Closes #1726


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/2df3eda4
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/2df3eda4
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/2df3eda4

Branch: refs/heads/python-sdk
Commit: 2df3eda4d6a84f3b1a8e5fea736cda8c57989a7b
Parents: 020daa9 e6b9bbc
Author: Robert Bradshaw <ro...@google.com>
Authored: Tue Jan 3 11:28:08 2017 -0800
Committer: Robert Bradshaw <ro...@google.com>
Committed: Tue Jan 3 11:28:08 2017 -0800

----------------------------------------------------------------------
 sdks/python/README.md | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
----------------------------------------------------------------------