1 Star 1 Fork 2

huahua456123/pyspark

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DStream.py 564 Bytes
一键复制 编辑 原始数据 按行查看 历史
huahua456123 提交于 2019-09-24 22:09 +08:00 . Add files via upload
# 创建StreamingContext对象
from pyspark import SparkConf, SparkContext
from pyspark.streaming import StreamingContext
conf = SparkConf()
conf.setAppName('TestDstream')
conf.setMaster('local[2]')
sc = SparkContext(conf=conf)
ssc = StreamingContext(sc, 10) # 每隔10秒去启动一次流计算
lines = ssc.textFileStream('file:///C:/Users/Lenovo/Desktop/streaming.txt')
words = lines.flatMap(lambda line: line.split(' '))
wordCounts = words.map(lambda x: (x, 1)).reduceByKey(lambda a, b: a+b)
wordCounts.pprint()
ssc.start()
ssc.awaitTermination()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/huahua456123/pyspark.git
git@gitee.com:huahua456123/pyspark.git
huahua456123
pyspark
pyspark
master

搜索帮助