【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

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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值