Skip to content

Commit ae464e0

Browse files
Ken TakagiwaKen Takagiwa
Ken Takagiwa
authored and
Ken Takagiwa
committed
edit python sparkstreaming example
1 parent 04af046 commit ae464e0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
import sys
22
from operator import add
33

4+
from pyspark.conf import SparkConf
45
from pyspark.streaming.context import StreamingContext
56
from pyspark.streaming.duration import *
67

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

examples/src/main/python/streaming/wordcount.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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

0 commit comments

Comments
 (0)