二次排序
来源:互联网 发布:阿里云服务器宽带价格 编辑:程序博客网 时间:2024/04/29 18:52
在第一字段有序的基础上第二字段也排序
比如要获取如下结果
1,2
1,3
1,4
2,3
2,4
3,4
方法1:Reduce内排序
class Mapper method Map(first f,second s) Emit(first f,second s)class Reducer method Reduce(first f, second [s1,s2,s3...]) sort([s1,s2,s3]) for second s in [s1,s2,s3] do Emit(first f,second s)
思路是先收集起同一key的所有数据,在reduce端进行value的排序
缺点是reduce端必须保存所有的value值,如果单一key对应的数据少,那么无所谓;如果value值多到内存放不下,那么就难以进行排序
处理示例
1,3 => map => 1,3 => reduce => 1,2
1,4 1,4 1,3
1,2 1,2 1,4
方法2:利用执行机制排序
class Mapper method Map(first f,second s) Emit(Pair<first f, second s>,second s)
思路是既然执行时要对key排序,那么把value也引入key中,在维持key的分组作用的同时排序value
key变成了复合内容,引入了s,可以用于实现second排序
重写Partitioner,first相同的分到一起
重写GroupComparator ,first相同就是属于同一组
重写KeyComparator,先比较first,分不出大小再比较second
Reducer 拿到数据时已经是排序好的,直接输出即可
处理示例
1,3 => map => (1,3),3 => (1,2),2 => reduce => 1,2
1,4 (1,4),4 (1,3),3 1,3
1,2 (1,2),2 (1,4),4 1,4
- 二次排序
- 二次排序
- 二次排序
- hadoop 二次排序
- InverseMapper.class二次排序
- Hadoop二次排序
- Hadoop二次排序
- Hadoop二次排序
- hadoop二次排序
- hadoop之二次排序
- hadoop二次排序一
- hadoop二次排序二
- hadoop二次排序三
- Hadoop二次排序
- mapreduce二次排序
- hadoop的二次排序
- MapReduce中二次排序
- Hadoop二次排序<转>
- quantile-quantile plot (qqplot) of the p-values
- git 使用小技巧
- Object serialization
- Joomla学习–如何在文章中插入模块
- svn的基本使用方法
- 二次排序
- 关于grep中$_的使用
- 固定在屏幕恒定位置的div层
- Linux内核中CPU主频和电压调整 (三)
- Math 使用
- poj 3101 大整数最小公倍数+欧几里得
- Winsock API: WSAStartup
- these query results are not updateable
- little script for speaker voice on office laptop