zoukankan      html  css  js  c++  java
  • grouping sets,cube,rollup,grouping__id,group by

    例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

  • 相关阅读:
    简单的REST的框架实现
    将 Shiro 作为一个许可为基础的应用程序 五:password加密/解密Spring应用
    Java自注三进入
    hdu 4803 贪心/思维题
    SSH框架总结(框架分析+环境搭建+实例源代码下载)
    Rational Rose 2007 &Rational Rose 2003 下载及破解方法和汉化文件下载
    hdu 5014 思维题/推理
    电脑蓝屏出现事件7000
    大豆生物柴油驱动的大巴斯(Bus)
    POJ 3481 & HDU 1908 Double Queue (map运用)
  • 原文地址:https://www.cnblogs.com/dudumiaomiao/p/4813149.html
Copyright © 2011-2022 走看看