- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSparkFolderFileStreaming.py
More file actions
Latest commit
26 lines (19 loc) · 695 Bytes
/
Copy pathSparkFolderFileStreaming.py
File metadata and controls
26 lines (19 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from __future__ importprint_function
importsys
frompysparkimportSparkContext
frompyspark.streamingimportStreamingContext
deflinesplit(line):
returnline.split(" ")
if__name__=="__main__":
# if len(sys.argv) != 2:
# print("Usage: hdfs_wordcount.py <directory>", file=sys.stderr)
# exit(-1)
sc=SparkContext("local[4]",appName="PythonStreamingHDFSWordCount")
ssc=StreamingContext(sc, 5)
lines=ssc.textFileStream("input")
counts=lines.flatMap(linesplit)\
.map(lambdax: (x, 1))\
.reduceByKey(lambdaa, b: a+b)
counts.saveAsTextFiles("output/Counts")
ssc.start()
ssc.awaitTermination()