Skip to content

Commit

Permalink
clean up exmples
Browse files Browse the repository at this point in the history
  • Loading branch information
giwa committed Aug 21, 2014
1 parent 24f95db commit 9c85e48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
9 changes: 4 additions & 5 deletions examples/src/main/python/streaming/network_wordcount.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
from operator import add

from pyspark.streaming.context import StreamingContext
from pyspark.streaming.duration import *
Expand All @@ -12,10 +11,10 @@
duration=Seconds(1))

lines = ssc.socketTextStream(sys.argv[1], int(sys.argv[2]))
words = lines.flatMap(lambda line: line.split(" "))
mapped_words = words.map(lambda word: (word, 1))
count = mapped_words.reduceByKey(add)
count.pyprint()
counts = lines.flatMap(lambda line: line.split(" "))\
.map(lambda word: (word, 1))\
.reduceByKey(lambda a,b: a+b)
counts.pyprint()

ssc.start()
ssc.awaitTermination()
11 changes: 6 additions & 5 deletions examples/src/main/python/streaming/wordcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
print >> sys.stderr, "Usage: wordcount <directory>"
exit(-1)

ssc = StreamingContext(appName="PythonStreamingWordCount", duration=Seconds(1))
ssc = StreamingContext(appName="PythonStreamingWordCount",
duration=Seconds(1))

lines = ssc.textFileStream(sys.argv[1])
words = lines.flatMap(lambda line: line.split(" "))
mapped_words = words.map(lambda x: (x, 1))
count = mapped_words.reduceByKey(lambda a, b: a+b)
count.pyprint()
counts = lines.flatMap(lambda line: line.split(" "))\
.map(lambda x: (x, 1))\
.reduceByKey(lambda a, b: a+b)
counts.pyprint()

ssc.start()
ssc.awaitTermination()

0 comments on commit 9c85e48

Please sign in to comment.