大数据-Hadoop生态(19)-MapReduce框架原理-Combiner合并

Posted duoduotouhenying

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了大数据-Hadoop生态(19)-MapReduce框架原理-Combiner合并相关的知识,希望对你有一定的参考价值。

1. Combiner概述

技术分享图片

 

 2. 自定义Combiner实现步骤

1). 定义一个Combiner继承Reducer,重写reduce方法

public class WordcountCombiner extends Reducer<Text, IntWritable, Text,IntWritable>{

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values,Context context) throws IOException, InterruptedException {

        // 1 汇总操作
        int count = 0;
        for(IntWritable v :values){
            count += v.get();
        }

        // 2 写出
        context.write(key, new IntWritable(count));
    }
}

2). 在Driver类中添加设置

job.setCombinerClass(WordcountCombiner.class);

 

效果

技术分享图片

 

 技术分享图片

 

以上是关于大数据-Hadoop生态(19)-MapReduce框架原理-Combiner合并的主要内容,如果未能解决你的问题,请参考以下文章