【发布时间】:2012-10-04 18:46:08
【问题描述】:
我是 hadoop 框架和 map reduce 抽象的新手。
基本上,我想在一个巨大的文本文件中找到最小的数字(用“,”分隔)
所以,这是我的代码 映射器.py
#!/usr/bin/env python
import sys
# input comes from STDIN (standard input)
for line in sys.stdin:
# remove leading and trailing whitespace
line = line.strip()
# split the line into words
numbers = line.split(",")
# increase counters
for number in numbers:
# 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; the trivial word count is 1
print '%s\t%s' % (number, 1)
减速器
#!/usr/bin/env python
from operator import itemgetter
import sys
smallest_number = sys.float_info.max
for line in sys.stdin:
# remove leading and trailing whitespace
line = line.strip()
# parse the input we got from mapper.py
number, count = line.split('\t', 1)
try:
number = float(number)
except ValueError:
continue
if number < smallest_number:
smallest_number = number
print smallest_number <---- i think the error is here... there is no key value thingy
print smallest_number
我得到的错误:
12/10/04 12:07:22 ERROR streaming.StreamJob: Job not successful. Error: NA
12/10/04 12:07:22 INFO streaming.StreamJob: killJob...
Streaming Command Failed!
【问题讨论】:
-
你得到什么样的结果?有什么问题?你在说什么“关键值”?
-
@Junuxx:嗨..我刚刚发布了错误..基本上..地图如何减少在文本文件中查找最小数字的抽象看起来像?/我正在谈论的错误是.. mapper 给出的 (number,1) 格式与 word count 示例中的 mapper 基本相同。在 reducer 中,我只关心数字。我取数字并将其与当前最小的数字进行比较并进行交换?
-
在没有 Hadoop 的情况下调试可能会有所帮助:
cat input | ./mapper.py | sort | ./reducer.py这是否运行成功? -
@MattD:不,我得到了这个回声“1,2,44,2”| mapper.py :没有这样的文件或目录我做了 chmod +x mapper.py 并且我在同一个目录中?我不知道为什么它找不到文件
-
@MattD:谢谢。我发现了错误:)
标签: python hadoop mapreduce hadoop-streaming