Esper EPL 模式仅触发一次

Esper EPL pattern fires only once

我正在尝试在 EPL 中创建一个模式,但我不明白为什么它只匹配一个。这是我在网页 Esper EPL online 上所做的。我在左侧文本框中输入的 EPL 是:

create schema StockTick(signature string, source string, destination string, action string);
@Name('Monitor') select * from StockTick;
@Name('Out') select * from pattern [A=StockTick -> B=StockTick(B.source = A.source and B.destination = A.destination and B.action='block') where timer:within(2 seconds)];

我在中间的文本框中输入的事件是:

StockTick={signature='sig1', source ='s1', destination ='d1'}
t=t.plus(0.4 seconds)

StockTick={source ='s1', destination ='d1', action='block'}
t=t.plus(0.4 seconds)

StockTick={signature='sig2', source ='s2', destination ='d2'}
t=t.plus(0.4 seconds)

StockTick={source ='s2', destination ='d2', action='block'}
t=t.plus(0.4 seconds)

我在右框中得到的输出:

At: 2001-01-01 08:00:00.000
Statement: Monitor
Insert
StockTick={signature='sig1', source='s1', destination='d1', action=(null)}

At: 2001-01-01 08:00:00.400
Statement: Monitor
Insert
StockTick={signature=(null), source='s1', destination='d1', action='block'}
Statement: Out
Insert
stmt2_pat_0_1={A={StockTick={signature='sig1', source='s1', destination='d1', action=(null)}}, B={StockTick={signature=(null), source='s1', destination='d1', action='block'}}}

At: 2001-01-01 08:00:00.800
Statement: Monitor
Insert
StockTick={signature='sig2', source='s2', destination='d2', action=(null)}
At: 2001-01-01 08:00:01.200
Statement: Monitor
Insert
StockTick={signature=(null), source='s2', destination='d2', action='block'}

所以:

我不明白的是为什么在 1.2 秒后我没有像我预期的那样再次触发 Out 语句。

请注意,如果我单独尝试前两个插入和后两个插入,在这两种情况下,我都会触发两次 Monitor 语句和一次触发 Out 语句。当我连接四个插入语句时出现问题。

感谢another forum,我设法解决了这个问题。我在定义模式时错过了 every 关键字,因此,在更新规则后如下:

@Name('Out') select * from pattern [every A=StockTick -> B=StockTick(B.source = A.source and B.destination = A.destination and B.action='block')];

它就像一个魅力:

At: 2001-01-01 08:00:00.000
Statement: Monitor
Insert
StockTick={signature='sig1', source='s1', destination='d1', action=(null)}

At: 2001-01-01 08:00:00.400
Statement: Monitor
Insert
StockTick={signature=(null), source='s1', destination='d1', action='block'}
Statement: Out
Insert
stmt2_pat_0_0={A={StockTick={signature='sig1', source='s1', destination='d1', action=(null)}}, B={StockTick={signature=(null), source='s1', destination='d1', action='block'}}}

At: 2001-01-01 08:00:00.800
Statement: Monitor
Insert
StockTick={signature='sig2', source='s2', destination='d2', action=(null)}

At: 2001-01-01 08:00:01.200
Statement: Monitor
Insert
StockTick={signature=(null), source='s2', destination='d2', action='block'}
Statement: Out
Insert
stmt2_pat_0_0={A={StockTick={signature='sig2', source='s2', destination='d2', action=(null)}}, B={StockTick={signature=(null), source='s2', destination='d2', action='block'}}}