首页 > 解决方案 > 如何在 FlinkSQL 的 SESSION 窗口中获取 LAST_VALUE?

问题描述

我在 Flink SQL (1.13) 中使用会话窗口。有没有办法(必须在 SQL 中,没有 UDF 等)来获取某个字段的最后一个值(换句话说:这将是 的值window_end)?我正在尝试:

SELECT user_account_id, 
       SESSION_START(request_timestamp, INTERVAL '30' MINUTE) AS window_start, 
       SESSION_END(request_timestamp, INTERVAL '30' MINUTE) AS window_end,
       LAST_VALUE(package)
GROUP BY SESSION(request_timestamp, INTERVAL '30' MINUTE), user_account_id

但我收到错误:

Could not find an implementation method 'merge' in class 'org.apache.flink.table.planner.functions.aggfunctions.LastValueAggFunction' for function 'LAST_VALUE' that matches the following signature:
void merge(org.apache.flink.table.data.RowData, java.lang.Iterable)

我猜想在这里使用窗口函数 ( OVER(...)) 是行不通的。任何提示表示赞赏!

标签: apache-flinkflink-sql

解决方案


我得到的答案是这还不被支持。一种解决方法是创建自定义用户定义的聚合函数 (UDAGG)。除此之外,该功能还有一个新的Jira


推荐阅读