[解决方案]spark 2.4 报错:grouping expressions sequence is empty, *** is not an aggregate function.

写在最前面

这里仅讨论spark 升级到 2.4 过程中 having 条件语句导致报错的情形,其他情形请参考 Spark中进行聚合时的特殊场景

一、报错详情

code

select id
	, content_map
from test_db.test_tb
having content_map is not null 

error

grouping expressions sequence is empty, and 'test_db.test_tb
.`id`' is not an aggregate function. Wrap '()' in windowing function(s) or wrap 'test_db.test_tb
.`id`' in first() (or first_value) if you don't care which value you get.;;

二、分析原因

在 spark 2.3 中,上面的 sql 执行正常,升级至 2.4 后才报错。主要的原因在于这两个版本对 having 条件语句计算逻辑不一样,2.4 执行过程中将 having 条件语句视为聚合运算后的一种过滤操作。源码中的解释:

In case of HAVING (a filter after an aggregate) we use both the aggregate and its child for resolution.

参考 源码解释Spark中进行聚合时的特殊场景

三、解决方案

替换 having 条件表达,例如换成 where 条件。

select id
	, content_map
from test_db.test_tb
where content_map is not null 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sinsa_SI

您的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值