小编cow*_*irl的帖子

根据reducer的值升序排序

我是 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)

java hadoop mapreduce hadoop2

2
推荐指数
1
解决办法
1467
查看次数

标签 统计

hadoop ×1

hadoop2 ×1

java ×1

mapreduce ×1