File tree Expand file tree Collapse file tree 2 files changed +6
-12
lines changed
examples/src/main/python/streaming Expand file tree Collapse file tree 2 files changed +6
-12
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
54from pyspark .streaming .context import StreamingContext
65from pyspark .streaming .duration import *
76
87if __name__ == "__main__" :
98 if len (sys .argv ) != 3 :
109 print >> sys .stderr , "Usage: wordcount <hostname> <port>"
1110 exit (- 1 )
12- conf = SparkConf ()
13- conf .setAppName ("PythonStreamingNetworkWordCount" )
14- ssc = StreamingContext (conf = conf , duration = Seconds (1 ))
11+ ssc = StreamingContext (appName = "PythonStreamingNetworkWordCount" ,
12+ duration = Seconds (1 ))
1513
1614 lines = ssc .socketTextStream (sys .argv [1 ], int (sys .argv [2 ]))
1715 words = lines .flatMap (lambda line : line .split (" " ))
1816 mapped_words = words .map (lambda word : (word , 1 ))
1917 count = mapped_words .reduceByKey (add )
20-
2118 count .pyprint ()
19+
2220 ssc .start ()
2321 ssc .awaitTermination ()
Original file line number Diff line number Diff line change 11import sys
2- from operator import add
32
4- from pyspark .conf import SparkConf
53from pyspark .streaming .context import StreamingContext
64from pyspark .streaming .duration import *
75
86if __name__ == "__main__" :
97 if len (sys .argv ) != 2 :
108 print >> sys .stderr , "Usage: wordcount <directory>"
119 exit (- 1 )
12- conf = SparkConf ()
13- conf .setAppName ("PythonStreamingWordCount" )
1410
15- ssc = StreamingContext (conf = conf , duration = Seconds (1 ))
11+ ssc = StreamingContext (appName = "PythonStreamingWordCount" , duration = Seconds (1 ))
1612
1713 lines = ssc .textFileStream (sys .argv [1 ])
1814 words = lines .flatMap (lambda line : line .split (" " ))
1915 mapped_words = words .map (lambda x : (x , 1 ))
20- count = mapped_words .reduceByKey (add )
21-
16+ count = mapped_words .reduceByKey (lambda a , b : a + b )
2217 count .pyprint ()
18+
2319 ssc .start ()
2420 ssc .awaitTermination ()
You can’t perform that action at this time.
0 commit comments