forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 6
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 16, 2014
1 parent
6d012f7
commit 1e84f41
Showing
1 changed file
with
22 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import sys | ||
from operator import add | ||
|
||
from pyspark.streaming.context import StreamingContext | ||
from pyspark.streaming.duration import * | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 3: | ||
print >> sys.stderr, "Usage: wordcount <hostname> <port>" | ||
exit(-1) | ||
ssc = StreamingContext(appName="PythonStreamingNetworkWordCount", duration=Seconds(1)) | ||
|
||
lines = ssc.socketTextStream(sys.argv[1], sys.argv[2]) | ||
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)) | ||
|
||
fm_lines.pyprint() | ||
filtered_lines.pyprint() | ||
mapped_lines.pyprint() | ||
ssc.start() | ||
ssc.awaitTermination() |