我们可以在 Flink 中结合计数和处理时间触发器吗? [英] Can we combine both and count and process time Trigger in Flink?

查看:24
本文介绍了我们可以在 Flink 中结合计数和处理时间触发器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让 Windows 在计数达到 100 或每 5 秒后完成翻滚处理时间?也就是说当元素达到100时,触发Windows计算,​​但是如果元素没有达到100,但时间过去了5秒,也会触发Windows计算,​​就像下面两个触发器的组合:

I want to make the Windows completed after the count reached 100 or every 5 seconds for the tumbling process time ? That is to say when the elements reached 100, trigger the Windows computation, however if the elements don't reache 100, but the time elapsed 5 seconds, it also trigger the Windows computation, just as the combination of the below two triggers:

.countWindow(100)

.countWindow(100)

.window(TumblingProcessingTimeWindows.of(Time.seconds(5)))

.window(TumblingProcessingTimeWindows.of(Time.seconds(5)))

推荐答案

目前的 Flink API 没有超级简单的方法来做到这一点.

There's no super simple way to do this with the current Flink API.

您的用例需要状态(用于计数)和计时器的组合.您可以使用自定义 触发,或使用 ProcessFunction.

Your use case needs a combination of state (for counting), and a timer. You can either accomplish this with windows using a custom Trigger, or by using a ProcessFunction.

对于使用 windows 和自定义触发器的方法,请查看 实现 会很有帮助,因为您基本上希望将两者混合.

For the approach with windows plus a custom trigger, looking at the implementations of ProcessingTimeTrigger and CountTrigger will be helpful, as you basically want to blend the two.

ProcessFunction 是一个较低级别的构建块,它将托管状态与计时器相结合,这正是您所需要的,因此这可能更容易,尤其是如果您已经知道如何使用 Flink 的托管状态.

ProcessFunction is a lower-level building block that combines managed state with timers, which is exactly what you need, so this is probably easier, especially if you already know how to work with Flink's managed state.

顺便说一句,在线 Flink 培训 包括学习如何使用 ProcessFunctions 的材料.

BTW, the online Flink training include materials for learning how to use ProcessFunctions.

这篇关于我们可以在 Flink 中结合计数和处理时间触发器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆