Skip to content

Commit

Permalink
initial commit for socketTextStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Takagiwa authored and giwa committed Sep 20, 2014
1 parent bb7ccf3 commit f746109
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/src/main/python/streaming/nerwork_wordcount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
from operator import add

from pyspark.streaming.context import StreamingContext
from pyspark.streaming.duration import *

if __name__ == "__main__":
if len(sys.argv) != 3:
print >> sys.stderr, "Usage: wordcount <hostname> <port>"
exit(-1)
ssc = StreamingContext(appName="PythonStreamingNetworkWordCount", duration=Seconds(1))

lines = ssc.socketTextStream(sys.argv[1], sys.argv[2])
fm_lines = lines.flatMap(lambda x: x.split(" "))
filtered_lines = fm_lines.filter(lambda line: "Spark" in line)
mapped_lines = fm_lines.map(lambda x: (x, 1))

fm_lines.pyprint()
filtered_lines.pyprint()
mapped_lines.pyprint()
ssc.start()
ssc.awaitTermination()

0 comments on commit f746109

Please sign in to comment.