我是 hadoop mapreduce 编程范例的新手,有人可以告诉我如何轻松地根据值进行排序吗?我尝试实现另一个比较器类,但是有没有更简单的方法,例如通过作业配置来根据减速器的值进行排序。基本上我正在阅读日志文件,并且我想按升序对 hitcount 进行排序。
public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
private final static IntWritable ONE = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
String[] split = value.toString().split(" ");
for(int i=0; i<split.length; i++){
if (i==6)
word.set(split[i]);
context.write(word, ONE);
}
}
}
public static class IntSumReducer extends Reducer<Text,IntWritable,Text,IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values, Context …Run Code Online (Sandbox Code Playgroud)