1 Star 17 Fork 16

NovemberRain/pyspark_project

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
spark0402.py 875 Bytes
一键复制 编辑 原始数据 按行查看 历史
迪卡普里奥 提交于 2019-11-03 13:27 +08:00 . pyspark
import sys
from pyspark import SparkConf, SparkContext
if __name__ == '__main__':
# 没有参数,就退出
if len(sys.argv) != 3:
print("Usage: wordcount <input> <output>", file=sys.stderr)
sys.exit(-1)
conf = SparkConf()
sc = SparkContext(conf=conf)
def printResult():
counts = sc.textFile(sys.argv[1]) \
.flatMap(lambda line: line.split("\t")) \
.map(lambda x: (x, 1)) \
.reduceByKey(lambda a, b: a + b)
output = counts.collect()
for (word, count) in output:
print("%s: %i" % (word, count))
def saveFile():
sc.textFile(sys.argv[1]) \
.flatMap(lambda line: line.split("\t")) \
.map(lambda x: (x, 1)) \
.reduceByKey(lambda a, b: a + b)\
.saveAsTextFile(sys.argv[2])
saveFile()
sc.stop()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cucy/pyspark_project.git
git@gitee.com:cucy/pyspark_project.git
cucy
pyspark_project
pyspark_project
master

搜索帮助