Skip to content

Commit b31446a

Browse files
Ken Takagiwagiwa
Ken Takagiwa
authored andcommitted
fixed typo of network_workdcount.py
1 parent ccfd214 commit b31446a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
from operator import add
3+
4+
from pyspark.streaming.context import StreamingContext
5+
from pyspark.streaming.duration import *
6+
7+
if __name__ == "__main__":
8+
if len(sys.argv) != 3:
9+
print >> sys.stderr, "Usage: wordcount <hostname> <port>"
10+
exit(-1)
11+
ssc = StreamingContext(appName="PythonStreamingNetworkWordCount", duration=Seconds(1))
12+
13+
lines = ssc.socketTextStream(sys.argv[1], int(sys.argv[2]))
14+
fm_lines = lines.flatMap(lambda x: x.split(" "))
15+
filtered_lines = fm_lines.filter(lambda line: "Spark" in line)
16+
mapped_lines = fm_lines.map(lambda x: (x, 1))
17+
18+
fm_lines.pyprint()
19+
filtered_lines.pyprint()
20+
mapped_lines.pyprint()
21+
ssc.start()
22+
ssc.awaitTermination()

0 commit comments

Comments
 (0)