我试图在Flink SQL的跳跃窗口上做一个指数衰减的移动平均值。我需要访问窗口的一个边框,以下是HOP_START:
SELECT
lb_index one_key,
-- I have access to this one:
HOP_START(proctime, INTERVAL '0.05' SECOND, INTERVAL '5' SECOND) start_time,
-- Aggregation primitive:
SUM(
Y * EXP(TIMESTAMPDIFF(
SECOND,
proctime,
-- This one throws:
HOP_START(proctime, INTERVAL '0.05' SECOND, INTERVAL '5' SECOND)
)))
FROM write_position
GROUP BY lb_index, HOP(proctime, INTERVAL '0.05' SECOND, INTERVAL '5' SECOND)
我得到以下堆栈跟踪:
11:55:37.011 [main] DEBUG o.a.c.p.RelOptPlanner - For final plan, using Aggregate(groupBy: (lb_index), window: (SlidingGroupWindow('w$, 'proctime, 5000.millis, 50.millis)), select: (lb_index, SUM($f2) AS Y, start('w$) AS w$start, end('w$) AS w$end, proctime('w$) AS w$proctime))
11:55:37.011 [main] DEBUG o.a.c.p.RelOptPlanner - For final plan, using Calc(select: (lb_index, proctime, *(payload.Y, EXP(/(CAST(/INT(Reinterpret(-(HOP_START(PROCTIME(proctime), 50, 5000), PROCTIME(proctime))), 1000)), 1000))) AS $f2))
11:55:37.011 [main] DEBUG o.a.c.p.RelOptPlanner - For final plan, using rel#459:DataStreamScan.DATASTREAM.true.Acc(table=[_DataStreamTable_0])
Exception in thread "main" org.apache.flink.table.codegen.CodeGenException: Unsupported call: HOP_START
If you think this function should be supported, you can create an issue and start a discussion for it.
at org.apache.flink.table.codegen.CodeGenerator$$anonfun$visitCall$3.apply(CodeGenerator.scala:1027)
at org.apache.flink.table.codegen.CodeGenerator$$anonfun$visitCall$3.apply(CodeGenerator.scala:1027)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.flink.table.codegen.CodeGenerator.visitCall(CodeGenerator.scala:1027)
at org.apache.flink.table.codegen.CodeGenerator.visitCall(CodeGenerator.scala:66)
它确实说它是未实现的,而它在聚合SUM之外工作。所以这就是我的观点,这是一个范围问题。
现在,问题是:我可以转换此表达式并在聚合之外进行最终处理,如exp(x + y)= exp(x)* exp(y);但我坚持使用TIMESTAMPDIFF(which did wonders in my previous issue)。我还没有找到将TIME ATTRIBUTE转换为NUMERIC类型的方法;另外,即使我缩小了UNIX时间戳,我也不习惯取代UNIX时间戳。
无论如何,这种解决方法有点笨拙,可能还有另一种方式。我不知道如何按下这个SQL片段中的范围仍然“在窗口范围内”,并且没有投掷的开始时间。
我建议你尝试使用HOP_PROCTIME()而不是HOP_START()。 here解释了这些差异,但效果将是你有一个proctime属性而不是一个时间戳,我希望这会使TIMESTAMPDIFF满意。