【问题标题】:FlinkCEP: Can I reference an earlier event to define a subsequent match?FlinkCEP:我可以参考更早的事件来定义后续匹配吗?
【发布时间】:2019-03-23 00:09:54
【问题描述】:

这是一个简单的例子:

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

本质上,第二个事件(“中间”)需要访问第一个事件(“开始”)的状态。是否可以在不需要外部状态的情况下在 FlinkCEP 中执行此操作?

【问题讨论】:

    标签: scala flink-cep


    【解决方案1】:

    当然。您可以借助 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;
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      • 2013-03-20
      • 1970-01-01
      相关资源
      最近更新 更多