File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed
examples/src/main/python/streaming Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change 11import sys
22from operator import add
33
4+ from pyspark .conf import SparkConf
45from pyspark .streaming .context import StreamingContext
56from pyspark .streaming .duration import *
67
78if __name__ == "__main__" :
89 if len (sys .argv ) != 3 :
910 print >> sys .stderr , "Usage: wordcount <hostname> <port>"
1011 exit (- 1 )
11- ssc = StreamingContext (appName = "PythonStreamingNetworkWordCount" , duration = Seconds (1 ))
12+ conf = SparkConf ()
13+ conf .setAppName ("PythonStreamingNetworkWordCount" )
14+ conf .set ("spark.default.parallelism" , 1 )
15+ ssc = StreamingContext (conf = conf , duration = Seconds (1 ))
1216
1317 lines = ssc .socketTextStream (sys .argv [1 ], int (sys .argv [2 ]))
1418 fm_lines = lines .flatMap (lambda x : x .split (" " ))
1519 filtered_lines = fm_lines .filter (lambda line : "Spark" in line )
1620 mapped_lines = fm_lines .map (lambda x : (x , 1 ))
21+ reduced_lines = mapped_lines .reduce (add )
1722
1823 fm_lines .pyprint ()
1924 filtered_lines .pyprint ()
2025 mapped_lines .pyprint ()
26+ reduced_lines .pyprint ()
2127 ssc .start ()
2228 ssc .awaitTermination ()
Original file line number Diff line number Diff line change 1313 conf .setAppName ("PythonStreamingWordCount" )
1414 conf .set ("spark.default.parallelism" , 1 )
1515
16+ # still has a bug
1617# ssc = StreamingContext(appName="PythonStreamingWordCount", duration=Seconds(1))
1718 ssc = StreamingContext (conf = conf , duration = Seconds (1 ))
1819
You can’t perform that action at this time.
0 commit comments