问题解决:Hive中双count(distinct)过慢的问题
来源:互联网 发布:struts2遍历标签数据加 编辑:程序博客网 时间:2024/06/18 03:09
这里说的双count(distinct)是指类似下面的语句
select day,count(distinct session_id),count(distinct user_id) from log a group by day;
如果要执行这样的语句,前提必须设置参数:set hive.groupby.skewindata=true;
我们可以用“空间换时间”的思路解决问题:
select day,count(case when type='session' then 1 else null end) as session_cnt, count(case when type='user' then 1 else null end) as user_cntfrom(select day,session_id,type from (select day,session_id,'session' as type from logunion allselect day user_id,'user' as typefrom log)group by day,session_id,type ) t1group by day
这里的type字段完全是自己定义的,目的就是通过多余的空间,将“查值”、“去重”、“累加1”操作分散到不同的mr任务里面去,起到提速的效果。
注意,type的取值个数和原语句中有几个count(distinct)是一致的,和session_id、user_id有多少种取值没关系。
阅读全文
0 0
- 问题解决:Hive中双count(distinct)过慢的问题
- hive count distinct
- hibernat 中 count和distinct的联用
- SQL 中 Count 和Distinct的使用
- Mysql中count(*),DISTINCT
- Hive SQL优化之 Count Distinct
- Hive SQL优化之 Count Distinct
- Hive SQL优化之 Count Distinct
- Informatica中实现count(distinct)
- Hibernate中使用COUNT DISTINCT
- BIEE中DISTINCT的问题
- Mysql中count(*),DISTINCT的使用方法和效率研究
- Mysql中count(*),DISTINCT的使用方法和效率研究
- Mysql中count(*),DISTINCT的使用方法和效率研究
- Mysql中count(*),DISTINCT的使用方法和效率研究
- sql中count函数和distinct函数的配合使用
- mysql 中 count()和distinct的一些杂想
- Mysql中count(*),DISTINCT的使用方法和效率研究
- 解决 textarea 没有value 无法显示默认文字
- 浅谈区块链技术
- 五种应该避免的代码注释
- Ionic 3 插件应用:plugin基本知识了解
- 20170905日记账流水(2017-09-05)
- 问题解决:Hive中双count(distinct)过慢的问题
- android-cooike的使用
- 研磨SpringCloud系列(一)第一个Spring Boot应用
- 【c++】映射表std::map
- ImageLoader_mainctivity
- Mysql Explain 详解
- 《angular2入门系列基础》——路由Route
- Linux学习---4
- Jedis操作