FlinkCEP:我可以引用一个较早的事件来定义一个后续的匹配吗? [英] FlinkCEP: Can I reference an earlier event to define a subsequent match?

查看:72
本文介绍了FlinkCEP:我可以引用一个较早的事件来定义一个后续的匹配吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的示例:

val pattern = 
   Pattern.begin[Event]("start").where(_.getId == 42).
   next("middle").subtype(classOf[SubEvent]).where(x => x.getVolume == **first event matched**.getVolume) ...

基本上,第二个事件(中间")需要访问第一个事件的状态(开始").是否可以在FlinkCEP中执行此操作而无需外部状态?

Essentially the second event ("middle") need to access the state of the first event ("start"). Is it possible to do this within FlinkCEP without requiring an external state?

推荐答案

好的.您可以借助Context获取特定模式的事件.

Sure. You can get events by for a specific pattern with the help of Context.

new IterativeCondition<Event>() {
            private static final long serialVersionUID = 8061969839441121955L;

            @Override
            public boolean filter(Event value, IterativeCondition.Context<Event> ctx) throws Exception {
                double sum = 0.0;
                for (Event e : ctx.getEventsForPattern("middle")) {
                    sum += e.getPrice();
                }
                return sum > 5.0;
            }
        }

这篇关于FlinkCEP:我可以引用一个较早的事件来定义一个后续的匹配吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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