首页 技术 正文
技术 2022年11月6日
0 收藏 742 点赞 577 浏览 2451 个字

例1:

hive -e”

select

type

,status

,count(1)

from

usr_info

where pt=’2015-09-14′

group by type,status

grouping sets ((type,status),( type),());

“>one.txt

Grouping sets按照各种指定聚类汇总方式,如group by type,status grouping sets ((type,status),( type),())

表示group by type,status union all  group by type union all group by ()

得到

type status       _c2

NULL         NULL         69467

1       NULL         68216

1       1       63615

1       2       540

1       4       4061

2       NULL         891

2       1       873

2       2       18

3       NULL         360

3       1       340

3       4       20

例2:

hive -e”

select

type

,status

,count(1)

from

usr_info

where pt=’2015-09-14′

group by type,status with rollup;

“>two.txt

group by type,status with rollup按照以type为主的固定聚类汇总方式,如同group by type,status grouping sets ((type,status),( type),()) ,不过形式已经固定了,表示group by type,status union all  group by type union all group by ()

得到

Type status      _c2

NULL         NULL         69467

1       NULL         68216

1       1       63615

1       2       540

1       4       4061

2       NULL         891

2       1       873

2       2       18

3       NULL         360

3       1       340

3       4       20

例3:

hive -e”

select

type

,status

,count(1)

from

usr_info

where pt=’2015-09-14′

group by type,status with cube;

“>three.txt

group by type,status with cube按照以type和status为主的固定聚类汇总方式,如同group by type,status grouping sets ((type,status),( type),(status),()) ,不过形式已经固定了,表示group by type,status union all group by type union all group by status union all group by ()

得到

Type status      _c2

NULL         NULL         69467

NULL         1       64828

NULL         2       558

NULL         4       4081

1       NULL         68216

1       1       63615

1       2       540

1       4       4061

2       NULL         891

2       1       873

2       2       18

3       NULL         360

3       1       340

3       4       20

例4:

hive -e”

select

type

,status

,grouping__id

,count(1)

from

usr_info

where pt=’2015-09-14′

group by type,status with cube;

“>five.txt

type

,status

,grouping__id

grouping__id(两条横线)函数判断其参数是否参与了分组,如果参与则返回1,如果没有参与了分组则返回0

而其多个参数的形式则将其每个参数进行grouping__id运算后返回的值拼成二进制后转换为十进制返回,

grouping_id(argn,…,arg2,arg1)=grouping_id(argn)*2^(n-1)+…+grouping_id(arg2)*2^1+grouping_id(arg1)*2^0(‘^’表示幂运算)。

Hive中grouping__id不带参数,用法见例子。

得到

type status    grouping__id   _c3

NULL         NULL         0       69467

NULL         1       2       64828

NULL         2       2       558

NULL         4       2       4081

1       NULL         1       68216

1       1       3       63615

1       2       3       540

1       4       3       4061

2       NULL         1       891

2       1       3       873

2       2       3       18

3       NULL         1       360

3       1       3       340

3       4       3       20

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903