首页 > 其他 > 详细

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

时间:2018-12-12 19:30:51      阅读:193      评论:0      收藏:0      [点我收藏+]

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合并

原文:https://www.cnblogs.com/duoduotouhenying/p/10110510.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!