我试图在亚马逊的弹性地图reduce上运行一个简单的单词计数map reduce作业,但是输出的结果是胡言乱语。输入文件是common crawl文件的一部分,这些文件是hadoop序列文件。该文件应该是从已爬网的网页中提取的文本(从html中剥离)。在
我的AWS Elastic MapReduce步骤如下所示:
Mapper: s3://com.gpanterov.scripts/mapper.py
Reducer: s3://com.gpanterov.scripts/reducer.py
Input S3 location: s3://aws-publicdatasets/common-crawl/parse-output/segment/1341690169105/textData-00112
Output S3 location: s3://com.gpanterov.output/job3/
作业运行成功,但是输出是杂乱无章的。只有奇怪的符号,根本没有文字。我猜这是因为hadoop序列文件不能通过标准读取?但是,如何在这样的文件上运行mr作业?我们必须先把序列文件转换成文本文件吗?在
第00000部分的前几行如下所示:
^{pr2}$这是我的地图:
#!/usr/bin/env python
import sys
for line in sys.stdin:
words = line.split()
for word in words:
print word + "\t" + str(1)
还有我的减速机:
#!/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)
输入文件没有问题。在本地计算机上,我运行hadoop fs -text textData-00112 | less
,这将从网页返回纯文本。
任何关于如何在这些类型的输入文件(常见的爬网hadoop序列文件)上运行python流式mapreduce作业的输入都是非常受欢迎的。在
您需要将
SequenceFileAsTextInputFormat
作为inputformat
提供给hadoop流媒体jar。在我从未使用过amazon aws mapreduce,但在正常的hadoop安装中,它会这样做:
Sunny Nanda的建议解决了这个问题。添加
-inputformat SequenceFileAsTextInputFormat
到aws弹性mapreduce API中的extra arguments框起作用,作业的输出如预期。在相关问题 更多 >
编程相关推荐