forked from alteryx/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ken Takagiwa
authored and
Ken Takagiwa
committed
Jul 17, 2014
1 parent
5720979
commit 571d52d
Showing
3 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
import sys | ||
from operator import add | ||
|
||
from pyspark.conf import SparkConf | ||
from pyspark.streaming.context import StreamingContext | ||
from pyspark.streaming.duration import * | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 2: | ||
print >> sys.stderr, "Usage: wordcount <directory>" | ||
exit(-1) | ||
ssc = StreamingContext(appName="PythonStreamingWordCount", duration=Seconds(1)) | ||
conf = SparkConf() | ||
conf.setAppName("PythonStreamingWordCount") | ||
conf.set("spark.default.parallelism", 1) | ||
|
||
# ssc = StreamingContext(appName="PythonStreamingWordCount", duration=Seconds(1)) | ||
ssc = StreamingContext(conf=conf, duration=Seconds(1)) | ||
|
||
lines = ssc.textFileStream(sys.argv[1]) | ||
fm_lines = lines.flatMap(lambda x: x.split(" ")) | ||
filtered_lines = fm_lines.filter(lambda line: "Spark" in line) | ||
mapped_lines = fm_lines.map(lambda x: (x, 1)) | ||
reduced_lines = mapped_lines.reduce(add) | ||
|
||
fm_lines.pyprint() | ||
filtered_lines.pyprint() | ||
mapped_lines.pyprint() | ||
reduced_lines.pyprint() | ||
ssc.start() | ||
ssc.awaitTermination() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters