[英]Sort in mapreduce
I am learning hadoop mapreducing. 我正在学习hadoop mapreducing。 I am trying to sort (by value) using mapreduce.
我正在尝试使用mapreduce排序(按值)。 Below is my code for the mapper:
下面是我的映射器代码:
static String splitChar = "\t";
static int colIndexone = 0;
static int colIndextwo = 1;
public static class MapClass extends MapReduceBase implements
Mapper<Object, Text, IntWritable, Text> {
public void map(Object key, Text value,
OutputCollector<IntWritable, Text> collector, Reporter arg3)
throws IOException {
int number;
String word = "empty";
String row = value.toString();
String colVals[] = row.split(splitChar);
word = colVals[colIndexone].toString();
number = Integer.parseInt(colVals[colIndextwo]);
collector.collect(new IntWritable(number), new Text(word));
}
}
Here I am reversing the pair so that, in the reducer I can sort based on the values. 在这里,我将对反转,以便在减速器中根据值进行排序。 I followed this .
我遵循了这一点 。
Now, can anyone help me how to approach for the reducer code! 现在,有人可以帮助我如何处理化简器代码!
Thanks in advance. 提前致谢。
UPDATE : 更新:
I wrote this as reducer 我写这个作为减速器
public static class Reduce extends MapReduceBase implements
Reducer<IntWritable, Text, IntWritable, Text> {
public void reduce(IntWritable key, Iterator<Text> values,
OutputCollector<IntWritable, Text> arg2, Reporter arg3)
throws IOException {
}
}
But how to get the sorted values? 但是如何获得排序后的值呢?
Solved: 解决了:
Below code is added to the reducer 下面的代码被添加到减速器中
while(values.hasNext()){
arg2.collect(key, (Text) values.next());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.