Skip to content

Commit b382a65

Browse files
author
Martin Durant
committed
Add wordcount example from spark
1 parent 8783b3f commit b382a65

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/network_wordcount.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /usr/env python
2+
""" a recreation of spark-streaming's network_wordcount
3+
4+
https://spark.apache.org/docs/2.2.0/streaming-programming-guide.html#a-quick-example
5+
6+
Run this within an interactive session, or with
7+
> python -i -network_wordcount.py
8+
so that python won't exit before producing output.
9+
"""
10+
11+
from streamz import Stream
12+
13+
# absolute port on localhost for now
14+
s = Stream.from_tcp(9999)
15+
s.map(bytes.split).flatten().frequencies().sink(print)
16+
17+
print(
18+
"""In another terminal executs
19+
> nc 127.0.0.1 9999
20+
and then start typing content
21+
"""
22+
)
23+
24+
s.start()

0 commit comments

Comments
 (0)