flinksqlbug : AggregateFunction udf Could not extract a data type from

这篇博客探讨了在使用 Flink SQL 时遇到的 AggregateFunction 类型推断错误,特别是关于 `CollectSetSort` 函数的问题。错误主要涉及类型不匹配和对 ArrayList 的不可访问字段。解决方案包括使用原始类型而非封装类型,并在 UDF 中返回 List 接口来避免访问私有方法的限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

org.apache.flink.table.api.ValidationException: SQL validation failed. An error occurred in the type inference logic of function ‘default_catalog.default_database.CollectSetSort’.
org.apache.flink.table.api.ValidationException: An error occurred in the type inference logic of function ‘default_catalog.default_database.CollectSetSort’.
org.apache.flink.table.api.ValidationException: Could not extract a valid type inference for function class ‘com.xiaomi.cloud.streaming.computing.udagg.CollectSetSort’. Please check for implementation mistakes and/or provide a corresponding hint.
org.apache.flink.table.api.ValidationException: Error in extracting a signature to accumulator mapping.
org.apache.flink.table.api.ValidationException: Unable to extract a type inference from method:
public void com.xiaomi.cloud.streaming.computing.udagg.CollectSetSort.accumulate(java.util.ArrayList,java.lang.Integer)
org.apache.flink.table.api.ValidationException: Could not extract a data type from ‘java.util.ArrayList<java.lang.Integer>’ in generic class ‘org.apache.flink.table.functions.AggregateFunction’ in class com.xiaomi.cloud.streaming.computing.udagg.CollectSetSort. Please pass the required data type manually or allow RAW types.
org.apache.flink.table.api.ValidationException: Could not extract a data type from ‘java.util.ArrayList<java.lang.Integer>’. Interpreting it as a structured type was also not successful.
org.apache.flink.table.api.ValidationException: Field ‘size’ of class ‘java.util.ArrayList’ is mutable but is neither publicly accessible nor does it have a corresponding setter method.

这个报错org.apache.flink.table.api.ValidationException: Could not extract a data type from ‘java.util.ArrayList<java.lang.Integer>’ in generic class ‘org.apache.flink.table.functions.AggregateFunction’ in class com.xiaomi.cloud.streaming.computing.udagg.CollectSetSort. Please pass the required data type manually or allow RAW types.

是因为我代码中AggregateFunction 定义的参数是 extends AggregateFunction<String, ArrayList>
java中的数据类型分两种 一个是基本类 一个是封装类。例如 数据类型int是Java中的基本数据类型,而Integer是int的封装类。

这里我用了封装类,导致无法解析数据类型,改用了 java.lang.long 直接声明引用就可以了。

另一个报错
org.apache.flink.table.api.ValidationException: Field ‘size’ of class ‘java.util.ArrayList’ is mutable but is neither publicly accessible nor does it have a corresponding setter method.

这是因为 ArrayList是封装类型,在udf中 访问其中的私有方法访问不到,所以应该用 List ,在创建的时候

在这里插入图片描述
返回List接口 就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Direction_Wind

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值