HIVE中Grouping sets 时遇见的问题

本文深入探讨了在Hive SQL中使用Grouping Sets时遇到的常见错误,具体分析了当聚合函数参数与分组字段重叠时Hive报错的情况,并提供了解决方案。在某些场景下,如使用pyspark时,该问题可能不会出现,但在Hive服务器上则需要特别注意。文章强调了分组字段不应出现在聚合条件中,建议在子查询中预先处理数据。

hive 中使用grouping SETS时遇见对坑

:hive报错

Grouping sets aggregations (with rollups or cubes) are not allowed if aggregation function parameters overlap with the aggregation functions columns
 

select  p.city_name,p.rent_type,p.sf_type,p.sign_type

,sum(case when rent_type= '合租' then 1 else 2 end )  as rooms 

from  rooms

group by  p.city_name,p.rent_type,p.sf_type,p.sign_type
grouping SETS(
p.city_name,
(p.city_name,p.rent_type),
(p.city_name,p.sf_type),
(p.city_name,p.sign_type),
(p.city_name,p.rent_type,p.sf_type),
(p.city_name,p.rent_type,p.sign_type),
(p.city_name,p.sf_type,p.sign_type),
(p.city_name,p.rent_type,p.sf_type,p.sign_type)
))b

在调试过程中 有些 平台是支持对比如 pyspark 

但在hive服务器有时候不支持

此时问题应该是 分组字段不应该出现在聚合条件里 ,所以再子数据里先处理roos 就好

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值