hive 排序
1、全局排序(order by)
Order by:全局排序,只有一个reducer
ASC(ascend):升序(默认)
DESC(descend):降序
2、每个MR内部排序(sort by)
sort By:对于大规模的数据集order by的效率非常低。在很多情况下,并不需要全局排序,此时可以使用sort by
Sort By为每个Reducer产生一个排序文件。每个Reducer内部进行排序,对全局结果集来说不是排序。
(1)设置reduce个数
hive (default)> set mapreduce.job.reduces=3;
(2)根据部分编号降序查看员工信息
hive (default)> select * from emp sort by empno desc;
3、分区排序(Distribute By)
Distribute By:在某些情况下,我们需要控制某个特定行应该到哪个Reducer,通常是为了后续的聚集操作。
Distribute by类似MR中partition(自定义分区),进行分区,结合sort by使用
测试时要分配多个reduce进行处理,否则无法看到Distribute by的效果
set mapreduce.job.reduces=3;
注意:
- Distribute by的分区规则是根据分区字段的hashcode与reduce的个数进行取模后,余数相同的分到一个区
- hive要求Distribute by语句要写在sort by语句之前
4、cluster by
当Distribute by 和sort by 字段相同时,可以使用cluster by 方式
cluster by除了具有distribute by的功能外还兼具sort by的功能。但是排序只能是升序排序,不能指定排序规则为ASC或者DESC。
1)以下两种写法等价
hive (default)> select * from emp cluster by deptno;
hive (default)> select * from emp distribute by deptno sort by deptno;
hive 排序的更多相关文章
- hive排序
1.升序排序 hive > select id,name,sal from emp order by sal; 2.降序 添加关键字desc hive > select id,nam ...
- hive 排序 分组计数后排序 几种不同函数的效果
[转至:http://blackproof.iteye.com/blog/2164260] 总结: 三个分析函数都是按照col1分组内从1开始排序 (假设4个数,第2和第3个数据相同) row_ ...
- hive 排序 order by sort by distribute by cluster by
order by: order by是全局排序,受hive.mapred.mode的影响. 使用orderby有一些限制: 1.在严格模式下(hive.mapred.mod ...
- hive 排序和聚集
1.order by 是对数据进行全排序,属于标准排序语句 order by 会对输入做全局排序,因此只有一个reducer(多个reducer无法保证全局有序)只有一个reducer,会导致当输入规 ...
- Hive基础之排序
order by 1.order by会对输入按照指定字段做全局排序,输出结果有序,因此只有一个reducer(多个reducer无法保证全局排序,手工设定reduce数量无效): 只有一个reduc ...
- Hive篇---Hive使用优化
一.前述 本节主要描述Hive的优化使用,Hive的优化着重强调一个 把Hive SQL 当做Mapreduce程序去优化 二.主要优化点 1.Hive运行方式:本地模式集群模式 本地模式开启本地模式 ...
- 【Hive学习之八】Hive 调优【重要】
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...
- hive学习(八)hive优化
Hive 优化 1.核心思想: 把Hive SQL 当做Mapreduce程序去优化 以下SQL不会转为Mapreduce来执行 select仅查询本表字段 where仅对本表字段做条件过滤 Ex ...
- hive常见的几种优化手段
Hive调优的几个入手点: Hive是基于Hadoop框架的,Hadoop框架又是运行在JVM中的,而JVM最终是要运行在操作系统之上的,所以,Hive的调优可以通过如下几个方面入手: 操作系统调优 ...
随机推荐
- Docker实战部署应用——Redis
Redis 部署 拉取Redis镜像 docker pull redis 创建Redis容器 docker run -id --name=sun_redis -p 6379:6379 redis 客户 ...
- C# 获取系统环境数据
using System; using System.Data; using System.Text.RegularExpressions; using System.Threading; names ...
- Nginx优化_自定义报错页面
自定义返回给客户端的404错误页面 1. 优化前,客户端使用浏览器访问不存在的页面,会提示404文件未找到 client]# firefox http://192.168.4.5/xxxxx ...
- Ubuntu 18.04 安装 CUDA 9.0
sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb sudo apt-key add /var/cuda-repo-< ...
- 【leetcode】1091. Shortest Path in Binary Matrix
题目如下: In an N by N square grid, each cell is either empty (0) or blocked (1). A clear path from top- ...
- 【leetcode】1041. Robot Bounded In Circle
题目如下: On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can recei ...
- VBA在Excel中的应用(三)
目录 Chart Export Chart Format Chart Lengend Chart Protect Chart Title Chart Chart Export 1. 将Exce ...
- 20180803-Java 流(Stream)、文件(File)和IO
Java 流(Stream).文件(File)和IO 下面的程序示范了用read()方法从控制台不断读取字符直到用户输入"q". // 使用BufferedReader 在控制台读 ...
- [CSP-S模拟测试]:回文(hash+二维前缀和)
题目描述 闲着无聊的$YGH$秒掉上面两道题之后,开始思考有趣的回文串问题了. 他面前就有一个漂浮着的字符串.显然$YGH$是会$manacher$的,于是他随手求出了这个字符串的回文子串个数.但是他 ...
- SQL利用Case When Then Else End 多条件判断
Select Case When a is not null then a When b is not null then b When c is not null then c When d is ...