小编Ska*_*ndy的帖子

在条件下停止Hadoop中的Reduce功能

我有一个reduce函数,我想在处理一些'n'键后暂停reduce函数.我已经设置了一个计数器来增加每个键,并且在满足条件时从reduce函数返回.

这是代码

    public class wordcount {

public static class Map extends Mapper<LongWritable, Text, IntWritable, IntWritable> {
        private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();
        private IntWritable leng=new IntWritable();

 public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();

        StringTokenizer tokenizer = new StringTokenizer(line);
         while (tokenizer.hasMoreTokens()) {
                String lword=tokenizer.nextToken(); 
            leng.set(lword.length());
             context.write(leng, one);
             }
        }
    } 

public static class Reduce extends Reducer<IntWritable, IntWritable, IntWritable, IntWritable> {

    int count=0;
        public void …
Run Code Online (Sandbox Code Playgroud)

reduce hadoop

3
推荐指数
1
解决办法
855
查看次数

标签 统计

hadoop ×1

reduce ×1