Hive中order by,sort by,distribute by,cluster by的区别
来源:互联网 发布:程序员穿正装 编辑:程序博客网 时间:2024/05/22 00:48
一:order by
order by会对输入做全局排序,因此只有一个Reducer(多个Reducer无法保证全局有序),然而只有一个Reducer,会导致当输入规模较大时,消耗较长的计算时间。关于order by的详细介绍请参考这篇文章:Hive Order by操作。
二:sort by
sort by不是全局排序,其在数据进入reducer前完成排序,因此,如果用sort by进行排序,并且设置mapred.reduce.tasks>1,则sort by只会保证每个reducer的输出有序,并不保证全局有序。sort by不同于order by,它不受hive.mapred.mode属性的影响,sort by的数据只能保证在同一个reduce中的数据可以按指定字段排序。使用sort by你可以指定执行的reduce个数(通过set mapred.reduce.tasks=n来指定),对输出的数据再执行归并排序,即可得到全部结果。
三:distribute by
distribute by是控制在map端如何拆分数据给reduce端的。hive会根据distribute by后面列,对应reduce的个数进行分发,默认是采用hash算法。sort by为每个reduce产生一个排序文件。在有些情况下,你需要控制某个特定行应该到哪个reducer,这通常是为了进行后续的聚集操作。distribute by刚好可以做这件事。因此,distribute by经常和sort by配合使用。
注:Distribute by和sort by的使用场景
1.Map输出的文件大小不均。
2.Reduce输出文件大小不均。
3.小文件过多。
4.文件超大。
四:cluster by
cluster by除了具有distribute by的功能外还兼具sort by的功能。但是排序只能是倒叙排序,不能指定排序规则为ASC或者DESC。
示例:
#sort by
hive (hive)> select * from user;OKidname1lavimer2liaozhongmin3liaozemin使用sort by按id降序排列:
hive (hive)> select * from user sort by id desc;//MapReduce...Execution completed successfullyMapred Local Task Succeeded . Convert the Join into MapJoinOKidname3liaozemin2liaozhongmin1lavimerTime taken: 3.828 seconds
#distribute by
hive (hive)> select * from user;OKidname1lavimer2liaozhongmin3liaozemin100hello200hadoop#设置reduce的个数
hive (hive)> set mapred.reduce.tasks=2;hive (hive)> set mapred.reduce.tasks; mapred.reduce.tasks=2
#使用带distribute by的数据从user表中导出数据
hive (hive)> insert overwrite local directory '/usr/local/src/user.txt' select * from user distribute by id;//MapReduce...Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 2注:从上述语句执行过程可以看到启动了两个Reducer。
#导出到本地的数据
[root@liaozhongmin5 src]# cd user.txt/[root@liaozhongmin5 user.txt]# ll总用量 8-rwxrwxrwx. 1 root root 36 1月 30 14:35 000000_0-rwxrwxrwx. 1 root root 22 1月 30 14:35 000001_0[root@liaozhongmin5 user.txt]# more 000000_0 2<span style="white-space:pre"></span>liaozhongmin100<span style="white-space:pre"></span>hello200<span style="white-space:pre"></span>hadoop[root@liaozhongmin5 user.txt]# more 000001_0 1<span style="white-space:pre"></span>lavimer3<span style="white-space:pre"></span>liaozemin[root@liaozhongmin5 user.txt]#注:从上述结果中,我们可以看到数据被分发到了两个Reducer中处理。
#distribute by和sort by结合使用
hive (hive)> select * from temperature;OKyeartempra200830`C200835`C200832.5`C200831.5`C200831`C201541`C201539`C201536`C201533`C201535`C201537`C#根据年份和气温对气象数据进行排序,以确保所具有相同年份的行最终都在一个reduce分区中。
hive (hive)> select * from temperature distribute by year sort by year asc,tempra desc;//MapReduce...Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 2//MapReduce...OKyeartempra200835`C200832.5`C200831`C200831.5`C200830`C201541`C201539`C201537`C201536`C201535`C201533`CTime taken: 17.358 seconds
- Hive中order by,sort by,distribute by,cluster by
- hive中order by,distribute by,sort by,cluster by
- hive中order by,sort by,distribute by,Cluster By的区别
- Hive中order by,sort by,distribute by,cluster by的区别
- Hive中order by,sort by,distribute by,cluster by的区别
- hive中order by、distribute by、sort by和cluster by的区别和联系
- Hive中order by,sort by,distribute by,cluster by的区别
- Hive中order by,sort by,distribute by,cluster by的区别
- Hive中order by,sort by,distribute by,cluster by的区别
- Hive中order by、sort by、distribute by、cluster by的区别
- hive Sort By/Order By/Cluster By/Distribute By
- hive中的order by+sort by+distribute by+cluster by
- Hive Sort by/Order By/Cluster By/Distribute By
- hive sort by,order by ,distribute by,cluster by
- Hive order by/sort by/distribute by/cluster by作用
- hive中的order by , sort by, distribute by, cluster by
- Hive-2.HiveQL查询中ORDER BY 和SORT BY 语句|包含SORT BY 的DISTRIBUTE BY|CLUSTER BY
- hive 中的Sort By、 Order By、Cluster By、Distribute By 区别<转>
- Spring配置文件中的C3P0数据源配置和事务配置(采用mysql)
- iOS 关于Images.xcassets LaunchImage各类图片解读
- Floodlight各模块处理PacketIn消息的顺序
- javax.net.ssl.SSLKeyException: RSA premaster secret error错误的解决办法
- JAVA 实现jpg/tif/bmp 等图片格式互相转换,解决RenderedOp资源不能释放
- Hive中order by,sort by,distribute by,cluster by的区别
- Object
- UVa #1149 Bin Packing (习题8-1)
- Android——菜单之SubMenu(子菜单)
- linux乱码问题:LANG变量的秘诀
- Zookeeper 的学习与运用
- CSDN学院讲师招募,诚邀您加入!
- 设置listview 中每个Item之间的间距
- JS:json对象和字符串之间的转换。