我正在学习hadoop MapReduce。我正在尝试使用mapreduce(按值)排序。下面是我的Map程序代码:
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));
}
}
在这里,我倒过来一对,这样,在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 {
}
}
但是如何得到排序后的值呢?
1条答案
按热度按时间bjp0bcyl1#
解决了的:
以下代码添加到减速器中