Skip to content

Commit 24f95db

Browse files
committed
clen up examples
1 parent 0d30109 commit 24f95db

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import sys
22
from operator import add
33

4-
from pyspark.conf import SparkConf
54
from pyspark.streaming.context import StreamingContext
65
from pyspark.streaming.duration import *
76

87
if __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()
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
import sys
2-
from operator import add
32

4-
from pyspark.conf import SparkConf
53
from pyspark.streaming.context import StreamingContext
64
from pyspark.streaming.duration import *
75

86
if __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()

0 commit comments

Comments
 (0)