hive count distinct
来源:互联网 发布:购买域名和空间 编辑:程序博客网 时间:2024/06/06 01:56
select count(distinct user_id) from dm_user where ds=20150701;
使用disticnt函数,所有的数据只会shuffle到一个reducer上,导致reducer数据倾斜严重
优化后为
set mapred.reduce.tasks=50;
select count(*) from
(select user_id from dm_user where ds=20150701 group by user_id)t;
order by全局排序,只有一个reduce
sort by 在一个reduce中排序,distribute by 按字段分为不同的reduce
distribute by 先分为不同的reduce排序,之后在reduce内部排序
// 一个reduce(海量数据,速度很慢)
select
year
, temperature
order
by
year
asc
, temperature
desc
limit 100;
替换成
// 多个reduce(海量数据,速度很快)
select
year
, temperature
distribute
by
year
sort
by
year
asc
, temperature
desc
limit 100;
order by (全局排序 )
order by 会对输入做全局排序,因此只有一个reducer(多个reducer无法保证全局有序)
只有一个reducer,会导致当输入规模较大时,需要较长的计算时间。
在hive.mapred.mode=strict模式下,强制必须添加limit限制,这么做的目的是减少reducer数据规模
例如,当限制limit 100时, 如果map的个数为50, 则reducer的输入规模为100*50
distribute by (类似于分桶)
根据distribute by指定的字段对数据进行划分到不同的输出reduce 文件中
sort by (类似于桶内排序)
sort by不是全局排序,其在数据进入reducer前完成排序。
因此,如果用sort by进行排序,并且设置mapred.reduce.tasks>1, 则sort by只保证每个reducer的输出有序,不保证全局有序。
cluster by
cluster by 除了具有 distribute by 的功能外还兼具 sort by 的功能。
但是排序只能是倒序排序,不能指定排序规则为asc 或者desc。
因此,常常认为cluster by = distribute by + sort by
0 0
- hive count distinct
- Hive SQL优化之 Count Distinct
- Hive SQL优化之 Count Distinct
- Hive SQL优化之 Count Distinct
- Hive 处理count distinct 产生数据倾斜处理
- HIVE group by 和count(distinct)进行对比
- 问题解决:Hive中双count(distinct)过慢的问题
- count(distinct)
- distinct() vs count()
- SQL(select distinct count)
- 处理 Distinct Count
- Mysql中count(*),DISTINCT
- SQL COUNT DISTINCT 函数
- mongodb count,distinct,group
- count(distinct user_id)
- SQL COUNT DISTINCT 函数
- mysql count if distinct
- hadoop-hive-DISTINCT
- spring的三种注入方式
- Intellij IDEA 上传本地项目到Git
- 【POJ 1151】Air Raid
- [寒江孤叶丶的Cocos2d-x之旅_37]获取LUA的父类方法
- socket阻塞与非阻塞,同步与异步、I/O模型 .
- hive count distinct
- Cordys HTML5 SDK BootStrap
- HTTP请求报文和HTTP响应报文 http://blog.csdn.net/zhangliang_571/article/details/23508953
- Nmap新增脚本http-svn-enum和http-svn-info
- SSH中各种形式的取值方式
- Mtalab--数据拟合
- 按层次方式打印二叉树
- HDU 2583 permutation
- 使用X-UA-Compatible来设置IE浏览器兼容模式