栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

【hive】 rollup的空值过滤

【hive】 rollup的空值过滤

rollup

rollup 用于hive在group by的顺序分组聚合,举例如下:

select  mac, stat_date,
        avg(cast(cpuOccupancyRate as int)) cpu_avg
from bidata.t_ods_pp_uplink_status_id
where stat_date>=20220119 and stat_date<=20220119
group by rollup(mac,stat_date)

输出结果:

macstat_datecpu_avg
NULLNULL3.8
30A176EDF550202201195.645833333333333
30A176EDAB70202201191.9148936170212767
30A176EDF550NULL5.645833333333333
30A176EDAB70NULL1.9148936170212767

以上内容可以看出,mac和stat_date会分别进行聚合,输出值为NULL,有时候不希望输出mac为NULL的结果,自然想到通过where mac is not null 进行过滤,实际验证

select * from
(
select  mac, stat_date,
        avg(cast(cpuOccupancyRate as int)) cpu_avg
from bidata.t_ods_pp_uplink_status_id
where stat_date>=20220119 and stat_date<=20220119
group by rollup(mac,stat_date)
) as t1 
where mac is not null

结果如下

macstat_datecpu_avg
NULLNULL3.8
30A176EDF550202201195.645833333333333
30A176EDAB70202201191.9148936170212767
30A176EDF550NULL5.645833333333333
30A176EDAB70NULL1.9148936170212767

为什么没有完成过滤呢?难道是NULL 不是空?是真的字符串值为NULL吗?经过验证,where mac!=‘NULL’,结果依然如上,满脸问号????
经过反复验证,解决方案如下:

select * from
(
select  NVL(mac,'mac') as mac, NVL(stat_date,'stat') as stat_date,
        avg(cast(cpuOccupancyRate as int)) cpu_avg
from bidata.t_ods_pp_uplink_status_id
where stat_date>=20220119 and stat_date<=20220119
group by rollup(mac,stat_date)
) as t1 
where mac != 'mac'

结果如下

macstat_datecpu_avg
30A176EDF550202201195.645833333333333
30A176EDAB70202201191.9148936170212767
30A176EDF550stat5.645833333333333
30A176EDAB70stat1.9148936170212767

为什么????还没找到原因,知道的同学求解答!!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/722947.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号