zoukankan      html  css  js  c++  java
  • Combiner

      如果job 设置了 combiner ,则job的每个map运行的数据会先进入combiner,然后再通过patitioner分发到reduce。通过combiner能减少reduce的计算、空间压力。其实combiner就是继承了Reducer类了一个子类,运行在map排序后的输出上。可以理解为,对每个map中的数据先做一次reduce。

    下面是一个例子,很简单,不多说了。

    	public static class MyCombiner extends Reducer<Text , Text , Text , Text>{
    		@Override
    		protected void reduce(Text key, Iterable<Text> values, Context context)
    				throws IOException, InterruptedException {
    			StringBuilder sb = new StringBuilder();
    			for(Text value : values){
    				sb.append(value.toString()).append(StrUtils.tab);
    			}
    			context.write(key, new Text(sb.toString().trim()));
    		}
    		
    	}
    

      

  • 相关阅读:
    大道至简阅读笔记01
    3.2-3.8 第三周总结
    全国疫情统计可视化地图 01
    数据爬取
    全国疫情统计可视化地图
    第3周总结
    第2周总结
    开课博客
    数组
    从小工到专家 读后感2
  • 原文地址:https://www.cnblogs.com/nocml/p/5148073.html
Copyright © 2011-2022 走看看