如何在单个 EPL 查询中匹配多个模式

How to match multiple patterns on single EPL query

我用 Esper 事件处理语言创建了两种不同的匹配识别模式,当我 运行 它们一个接一个地工作时,它们工作正常,但我需要从传入事件的这两种模式中获得结果。模式定义如下。

(1)

match_recognize( "
measures A as a, B as b "
pattern (A B) "
define "
A as A.scene= 'stock'and A.activity='assembly' and A.task='picking' and A.mod2='FT' and A.mod3='Scn', 
B as B.scene='stock' and B.activity='assembly' and B.task='picking' and B.mod2='PG' and B.mod3='GzS')

(2)

match_recognize( 
measures A as a, B as b, C as c 
pattern (A B C) 
define
A as A.scene= 'assembly'and A.activity='assembly' and A.task='moving' and A.mod2='GrS' and A.mod3='GzS', 
B as B.scene='assembly' and B.activity='assembly' and B.task='moving' and B.mod2='GrT' and B.mod3='Follow', 
C as C.scene='assembly' and C.activity='assembly' and C.task='moving' and C.mod2='GrT' and C.mod3='GzS')

当这些模式中的任何一个与单个查询中的传入事件匹配时,我需要获得结果。

好的,问题是什么?您可以简单地创建它们并为每个添加一个侦听器并完成所有操作。

第一个例子:

String epl = "@name('first') select ... from ...;\n";
epl += "@name('second') select ... from ...;\n";
epAdministrator.getDeploymentAdmin().parseDeploy(epl);
epAdministrator.getStatement('first').addListener(new MyListener());
epAdministrator.getStatement('second').addListener(new MyListener());

另一个例子:

EPStatement first = epAdministrator.createEPL(...);
first.addListener(new MyUpdateListener());
EPStatement second = epAdministrator.createEPL(...);
second.addListener(new MyUpdateListener());