前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Streaming执行Python版Wo

Streaming执行Python版Wo

作者头像
py3study
发布2020-01-06 15:15:04
4330
发布2020-01-06 15:15:04
举报
文章被收录于专栏:python3python3

一:先写map类

代码语言:javascript
复制
import sys
for line in sys.stdin:
line = line.strip( )
words = line.split( )
for word in words:
print('%s\t%s' % (word, 1))

二:写reduce类

代码语言:javascript
复制
import sys
current_word = None
current_count = 0
word = None
for line in sys.stdin:
line = line.strip()
word, count = line.split('\t',1)
try:
count = int(count)
except ValueError:
continue
if current_word == word:
current_count += count
else:
if current_word:
print('%s\t%s' % (current_word,current_count))
current_count = count
current_word = word
if current_word == word:
print('%s\t%s' % (current_word,current_count))

三:利用hadoop Streaming执行Python的内容。

hadoop jar /home/hadoop/hadoop-2.6.0-cdh5.5.2/share/hadoop/tools/lib/hadoop-streaming-2.6.0-cdh5.5.2.jar  -input /user/hadoop/aa.txt -output /user/hadoop/python_output -mapper "python mapper.py" -reducer "python reducer.py" -file mapper.py -file reducer.py

说明:

输入和输出路径,本身就是hdfs上的,不需要特殊指定hdfs。

不加×××部分的引号的话,会报错误:

Error: java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess failed with code 2

不加粉色部分的内容的话,会报错误:

Error: java.lang.RuntimeException: Error in configuring object

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
专用宿主机
专用宿主机(CVM Dedicated Host,CDH)提供用户独享的物理服务器资源,满足您资源独享、资源物理隔离、安全、合规需求。专用宿主机搭载了腾讯云虚拟化系统,购买之后,您可在其上灵活创建、管理多个自定义规格的云服务器实例,自主规划物理资源的使用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档