如何在Flink流中的空窗口上执行功能? [英] How to execute functions on empty windows in Flink streaming?

查看:95
本文介绍了如何在Flink流中的空窗口上执行功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个Flink程序,该程序从简单的kafka流计算每个键控窗口的事件数.我的作品很棒,快速且准确的.当源停止时,我想在每个窗口上将 0 作为计算的结果,但不发送任何结果.该功能只是不执行.我认为这是由于Flink的惰性操作行为所致.

I wrote a Flink program that calculates the number of events per keyed window from a simple kafka stream. I works great, fast & accurate. When the source stops, I would like to have 0 as result of the calculation on each window, but no result is sent. The function just does not execute. I assume this is because of the lazy operation behavior of Flink.

有什么建议吗?

推荐答案

我遇到了同样的情况.一种解决方法是填补数据库中的漏洞.

I encountered the same situation. Filling the holes in your database with another process is a solution.

但是,我发现将您的主流与自定义期刊来源合并起来会更容易,该期刊来源会发出假人,其唯一作用是触发Windows创建.这样做时,必须确保在计算中忽略了虚拟变量.

However, I found it easier to union your main stream with a custom periodical source, that emits dummies, whose only roles are to trigger windows creation. When doing this, you have to make sure that dummies are ignored in computations.

这里是如何编写期刊来源的代码(但是您可能不需要RichParallelSourceFunction,一个SourceFunction就足够了)

Here is how to code a periodical source (however you may not need a RichParallelSourceFunction, a SourceFunction can be enough)

这篇关于如何在Flink流中的空窗口上执行功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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