Python中文
首页
教程
问答
标签
搜索
登录
注册
无法使用AW上的流式python mapreduce通过stdin读取Hadoop序列文件
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我试图在亚马逊的弹性地图reduce上运行一个简单的单词计数map reduce作业,但是输出的结果是胡言乱语。输入文件是<a href="http://commoncrawl.org/" rel="nofollow">common crawl</a>文件的一部分,这些文件是hadoop序列文件。该文件应该是从已爬网的网页中提取的文本(从html中剥离)。在</p> <p>我的AWS Elastic MapReduce步骤如下所示:</p> <pre><code>Mapper: s3://com.gpanterov.scripts/mapper.py Reducer: s3://com.gpanterov.scripts/reducer.py Input S3 location: s3://aws-public<a href="https://www.cnpython.com/pypi/dataset" class="inner-link">dataset</a>s/common-crawl/parse-output/segment/1341690169105/textData-00112 Output S3 location: s3://com.gpanterov.output/job3/ </code></pre> <p>作业运行成功,但是输出是杂乱无章的。只有奇怪的符号,根本没有文字。我猜这是因为hadoop序列文件不能通过标准读取?但是,如何在这样的文件上运行mr作业?我们必须先把序列文件转换成文本文件吗?在</p> <p>第00000部分的前几行如下所示:</p> ^{pr2}$ <p>这是我的地图:</p> <pre><code>#!/usr/bin/env python import sys for line in sys.stdin: words = line.split() for word in words: print word + "\t" + str(1) </code></pre> <p>还有我的减速机:</p> <pre><code>#!/usr/bin/env python import sys def output(previous_key, total): if previous_key != None: print previous_key + " was found " + str(total) + " times" previous_key = None total = 0 for line in sys.stdin: key, value = line.split("\t", 1) if key != previous_key: output(previous_key, total) previous_key = key total = 0 total += int(value) output(previous_key, total) </code></pre> <p>输入文件没有问题。在本地计算机上,我运行<code>hadoop fs -text textData-00112 | less</code>,这将从网页返回纯文本。 任何关于如何在这些类型的输入文件(常见的爬网hadoop序列文件)上运行python流式mapreduce作业的输入都是非常受欢迎的。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>Sunny Nanda的建议解决了这个问题。添加 <code>-inputformat SequenceFileAsTextInputFormat</code> 到aws弹性mapreduce API中的extra arguments框起作用,作业的输出如预期。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何添加虚拟方法
2 回答
如何添加表示整数的擦边字符串?
7 回答
如何添加要在Bokeh中使用的新font.ttf文件?
1 回答
如何添加要显示的矩阵XY轴编号和XY轴
4 回答
如何添加计数?
6 回答
如何添加计数器函数?
3 回答
如何添加计数器列来计算数据帧中另一列中的特定值?
8 回答
如何添加计数器来跟踪while循环中的月份和年份?
9 回答
如何添加计数并删除countplot的顶部和右侧脊椎?
9 回答
如何添加计时器wx.应用程序更新窗口对象的主循环?
6 回答
如何添加评论到帖子?PostDetailVew,Django 2.1.5
5 回答
如何添加评论拉梅尔亚姆
1 回答
如何添加诸如矩阵Python/Pandas之类的数据帧?
3 回答
如何添加谷歌地点自动完成到Flask?
5 回答
如何添加超时、python discord bot
8 回答
如何添加超过1dp的检查
5 回答
如何添加距离方法
1 回答
如何添加跟随游戏的敌人精灵
9 回答
如何添加路径以便python可以找到程序?
4 回答
如何添加身份验证/安全性以使用happybase访问HBase?
10 回答