ハイブデータ分析5つのGROUPINGは、ウィンドウのGROUPING__ID CUBEロールアップ機能を設定します。

問題の解決:通常の状況下でのみ、あなたが達成するために、すべての複数の次元重合組合を使用する必要がある場合は、1つのディメンション・グループは、重合によるものであって、かつ機能のシリーズをグループ化することができますが、一度GROUPING SETS(月、日、(で達成することができ 、月、日)))日、2つ(月、日、ポリマー3月表す3つの
概要:
GROUPINGセット、GROUPING__ID、CUBE、ROLLUP
、これらの機能は、典型的には、OLAP分析で使用される累積しないだけでなく、異なる寸法に応じています例えばUV分の時間、日、月の数などの統計指標を、ドリルとドリル。
cookie5.txt

2015-03,2015-03-10,cookie1
2015-03,2015-03-10,cookie5
2015-03,2015-03-12,cookie7
2015-04,2015-04-12,cookie3
2015-04,2015-04-13,cookie2
2015-04,2015-04-13,cookie4
2015-04,2015-04-16,cookie4
2015-03,2015-03-10,cookie2
2015-03,2015-03-10,cookie3
2015-04,2015-04-12,cookie5
2015-04,2015-04-13,cookie6
2015-04,2015-04-15,cookie3
2015-04,2015-04-15,cookie2
2015-04,2015-04-16,cookie1
drop table if exists cookie5;
create table cookie5(month string, day string, cookieid string) 
row format delimited fields terminated by ',';
load data local inpath "/home/hadoop/cookie5.txt" into table cookie5;
select * from cookie5;


クエリBY GROUPにおいて、重合によれば、異なる寸法の組み合わせは、結果が異なる寸法属するパケットのセットの結果を示すUNION ALL GROUPING__IDを、設定されているGROUP BYと等価です。

遊ぶ
月と日が重合されます

 select 
  month,
  day,
  count(distinct cookieid) as uv,
  GROUPING__ID
from cookie5 
group by month,day 
grouping sets (month,day) 
order by GROUPING__ID;

に相当

SELECT month,NULL,COUNT(DISTINCT cookieid) AS uv,1 AS GROUPING__ID FROM cookie5 GROUP BY month 
UNION ALL 
SELECT NULL,day,COUNT(DISTINCT cookieid) AS uv,2 AS GROUPING__ID FROM cookie5 GROUP BY day


説明結果

第一列是按照month进行分组

第二列是按照day进行分组

第三列是按照month或day分组是,统计这一组有几个不同的cookieid

第四列grouping_id表示这一组结果属于哪个分组集合,
      根据grouping sets中的分组条件month,day,1是代表month,2是代表day

もう一つの例

SELECT  month, day,
COUNT(DISTINCT cookieid) AS uv,
GROUPING__ID 
FROM cookie5 
GROUP BY month,day 
GROUPING SETS (month,day,(month,day)) 
ORDER BY GROUPING__ID;

に相当

SELECT month,NULL,COUNT(DISTINCT cookieid) AS uv,0 AS GROUPING__ID FROM cookie5 GROUP BY month 
UNION ALL 
SELECT NULL,day,COUNT(DISTINCT cookieid) AS uv,1 AS GROUPING__ID FROM cookie5 GROUP BY day
UNION ALL 
SELECT month,day,COUNT(DISTINCT cookieid) AS uv,2 AS GROUPING__ID FROM cookie5 GROUP BY month,day

GROUPING SETS(月、日、(月、日)) 3つの重合に見られる
月:最初の
二:一日
三:(月、日)

おすすめ

転載: blog.csdn.net/weixin_42177380/article/details/90809586