【发布时间】:2014-05-27 03:38:00
【问题描述】:
我对 Hadoop 和 MapReduce 完全陌生,并且正在努力解决它。 我正在尝试在 python 中开发一个 mapreduce 应用程序,其中我使用来自 2 个 .CSV 文件的数据。我只是在 mapper 中读取这两个文件,然后将文件中的键值对打印到 sys.stdout
当我在单台机器上使用该程序时,它运行良好,但使用 Hadoop Streaming,我得到一个错误。我认为我在 Hadoop 上的映射器中读取文件时犯了一些错误。请帮我写代码,并告诉我如何在 Hadoop Streaming 中使用文件处理。 mapper.py 代码如下。 (从cmets可以看懂代码):
#!/usr/bin/env python
import sys
from numpy import genfromtxt
def read_input(inVal):
for line in inVal:
# split the line into words
yield line.strip()
def main(separator='\t'):
# input comes from STDIN (standard input)
labels=[]
data=[]
incoming = read_input(sys.stdin)
for vals in incoming:
# write the results to STDOUT (standard output);
# what we output here will be the input for the
# Reduce step, i.e. the input for reducer.py
#
# tab-delimited;
if len(vals) > 10:
data.append(vals)
else:
labels.append(vals)
for i in range(0,len(labels)):
print "%s%s%s\n" % (labels[i], separator, data[i])
if __name__ == "__main__":
main()
有 60000 条记录从两个 .csv 文件输入到此映射器,如下所示(在单机上,而不是 hadoop 集群上):
cat mnist_train_labels.csv mnist_train_data.csv | ./mapper.py
【问题讨论】:
-
Hadoop 流式读/写到 STDIO。检查 Hadoop Streaming (goo.gl/k6SjuH) 的工作原理,然后发布查询。
-
嗨,普拉文。我已经相应地更新了映射器代码,但在流式传输时仍然出现错误。错误是 - '容器被 Application Master 杀死。容器在请求时被杀死。退出代码是 143' 。在那之后,我收到很多错误,因为“子进程失败,代码为 1”。请帮我解决这些错误。谢谢...
标签: python hadoop mapreduce hadoop-streaming