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 就好

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

被折叠的 条评论
为什么被折叠?



