【发布时间】:2016-07-06 18:10:41
【问题描述】:
在 MapReduce 程序中,Reducer 方法将 Mapper 的输入作为“单词”及其长度。
ex.input :-
Hi -2
how - 3
are -3
you - 3
? - 1
现在我需要编写一个 Reducer,它通过对“字长”进行分组来提供输出,并且所有单词都根据字长归为一个类别,如下所示
ex. Output :-
1 - [?]
2 - [hi]
3 - [how, are, you]
这是我的 Mapper 程序:
public void map(LongWritable key, Text values, OutputCollector<Text, IntWritable> Output, Reporter arg3) throws IOException {
String s = values.toString();
for (String word : s.split(" ")) {
if (word.length() > 0 ) {
Output.collect(new Text(word), new IntWritable(word.length()));
}
}
}
Reduce 程序如何?
【问题讨论】:
-
无意冒犯,如果你不能设计一个像 MapReduce 那样简单的程序,也许你应该回去阅读一些 MapReduce 基础知识(例如,教程或书籍)。这将为您节省大量时间。
标签: java hadoop mapreduce iterator reducers