我正在学习hadoop地图还原。我正在尝试使用mapreduce(按值)进行排序。以下是我的映射程序代码:
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中,我可以根据值进行排序。我关注了这个。
现在,有人能帮助我如何处理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 {
}
}
但是如何获得排序后的值呢?
已解决:
以下代码添加到减速器
while(values.hasNext()){
arg2.collect(key, (Text) values.next());
}