Hadoop Combiner类 简单测试
2015-12-17 16:43
513 查看
public static class MyReduce extends Reducer<Text, IntWritable, Text, IntWritable>{ private static IntWritable num = new IntWritable(); @Override public void reduce(Text key,Iterable <IntWritable> val,Context context )throws IOException,InterruptedException { int sum=0; for(IntWritable each : val){ sum++; // 这是第一种情况 //sum += val.get(); // 这是第二种情况 // IntWritable.get(); 返回 IntWritable的int值 } num.set(sum); //返回值并非本对象 context.write(key, num); } }
接下来就是主函数的区别
job.setCombinerClass(MyReduce.class); // 是否加入Combiner对了,这是最简单的WordCount程序。
不加入Combiner时,两种情况答案正确。
加入后,只有第二种方法正确。
分析: 没有Combiner,map --> (word,(1,1,1,1)) --> reduce --> (word,4)
加入Combiner , map --> (word,(1,1,1,1)) -->(Combiner,仍在执行map的主机上) (word,(4)) --> reduce (word,(1))
// 所以加入Combiner后,第一种数集合中有多少元素的方法就失效了,输出的所有单词数量均为1。
因为这里Combiner和Reduce用相同的函数,即都是reduce( ); 所以reduce的后两个输出参数要和前两个参数类型一致。
相关文章推荐
- linux下Nginx+tomcat整合的安装与配置
- Linux下的Mysql笔记整理(二)
- Codeblocks下用自己的makefile
- Linux下的Mysql笔记整理(二)
- 关于苹果命令sed与centos使用的区别
- Apache+Tomcat集群配置
- getopt和getopt_long函数用法
- Linux资源使用配置文件 /etc/security/limits.conf
- 基于opencv的阈值分割
- nginx如何读取缓存文件
- 在CentOS上升级把Nginx
- 排序算法,堆算法实现TopK
- maven 定义profile.properties
- 如何从Apache官网下载windows版apache服务器
- linux 下防火墙iptables
- linux下who am i和whoami的区别
- centos安装图形化界面 和 安装火狐浏览器
- 【Linux 驱动】中断处理(二)下半部tasklet
- 理解nginx的配置
- Linux下国际化问题