`

hive海量数据--统计一年网站各个产品的UV

    博客分类:
  • hive
 
阅读更多

在做年终报表需要统计公司网站各个产品一年总的UV,抽出id,product到表year2012,数据条数大概为5千多亿条,由于数据量太大。

1 .

select  count(distinct id) as uv,product from  year2012  where log_date>='2012-01-01'  and log_date<='2012-12-31'  group by product;

 第一种方案显然不可取。

2.

select count(1) as uv,product  from (select id,product,sum(1) as c from year2012  where log_date>='2012-01-01' and log_date<='2012-12-31' group by id,product cluster by id,product) f group by product;

 第二种方案:map数9940    设置reduce数 100,运行时间为20分钟;

在遇到很多数据量时,需要多种转换,第二种方案,

第一个阶段:

根据id和product来分配该条记录分配到哪个reduce上:cluster by id ,然后用group by id,product去重;

第二阶段:

统计每个产品的条数即为该产品的uv。

 

分享到:
评论
1 楼 di1984HIT 2014-06-13  
大数据量分析。

相关推荐

Global site tag (gtag.js) - Google Analytics