FlinkCEP: Can I reference an earlier event to define a subsequent match?

心不动则不痛 提交于 2019-12-11 17:19:14

问题


Here is a simple example:

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

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?


回答1:


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;
            }
        }


来源:https://stackoverflow.com/questions/55309321/flinkcep-can-i-reference-an-earlier-event-to-define-a-subsequent-match

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!