单个规则中的多次重复

时间:2017-06-30 23:33:02

标签: esper

我试图在EPL中表达“在2秒内至少两个foo s后跟两个bar”的规则。我尝试过使用这两种模式和match_recognize,但我无法获得我想要的语义。我已经修改了在线EPL工具中的StockTick示例,以说明我正在做什么。

我尝试过以下两种模式:

select g[0].seq, g[1].seq, g[2].seq, g[3].seq, y[0].seq, y[1].seq from pattern [
     every ([2:] g=StockTick(symbol = 'GE') until timer:interval(2 sec)) -> not timer:interval(2 sec) and every [2] y=StockTick(symbol = 'YHOO')
];

select * from StockTick match_recognize (
   measures g[0].seq as g0_seq, g[1].seq as g1_seq, g[2].seq as g2_seq, g[3].seq as g3_seq, y[0].seq as y0_seq, y[1].seq as y1_seq
   pattern (g{2,} y{2})
   interval 2 sec
   define
       g as g.symbol = 'GE',
       y as y.symbol = 'YHOO'
);

用于以下事件定义:

create schema StockTick(seq int, symbol string);

关于以下输入:

StockTick={seq=1, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=2, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=3, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=4, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=5, symbol='YHOO'}
t=t.plus(200 msec)
StockTick={seq=6, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=7, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=8, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=9, symbol='YHOO'}
t=t.plus(200 msec)
StockTick={seq=10, symbol='YHOO'}
t=t.plus(200 msec)
StockTick={seq=11, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=12, symbol='YHOO'}
t=t.plus(200 msec)
StockTick={seq=13, symbol='YHOO'}
t=t.plus(200 msec)
StockTick={seq=14, symbol='YHOO'}
t=t.plus(200 msec)
StockTick={seq=15, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=16, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=17, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=18, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=19, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=20, symbol='YHOO'}
t=t.plus(200 msec)
StockTick={seq=21, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=22, symbol='YHOO'}
t=t.plus(200 msec)
StockTick={seq=23, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=24, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=25, symbol='GE'}
t=t.plus(200 msec)
StockTick={seq=26, symbol='GE'}

并获得以下输出:

At: 2001-01-01 08:00:02.400
Statement: Stmt-2
Insert
Stmt-2-output={g[0].seq=1, g[1].seq=2, g[2].seq=3, g[3].seq=4, y[0].seq=12, y[1].seq=13}
At: 2001-01-01 08:00:03.000
Statement: Stmt-3
Insert
Stmt-3-output={g0_sec=6, g1_sec=7, g2_sec=8, g3_seq=(null), y0_seq=9, y1_seq=10}
At: 2001-01-01 08:00:03.800
Statement: Stmt-2
Insert
Stmt-2-output={g[0].seq=1, g[1].seq=2, g[2].seq=3, g[3].seq=4, y[0].seq=14, y[1].seq=20}

我理解第一个EPL语句,until timer:interval(2 sec)与我实际想要的逻辑不符,但我不确定如何表达它。

我尝试将窗口(#time(2 sec))附加到模式而不改变输出。

我希望获得以下序列号的匹配:

(1, 2, 3, 4, 5, 9)
(1, 2, 3, 4, 9, 10)
(2, 3, 4, 6, 9, 10)
etc.

这样就可以为每2秒窗口评估规则,并在每个窗口中获得最长的g序列。

1 个答案:

答案 0 :(得分:0)

"间隔"在match-recognition中有不同的含义。你想要的是这个:

select * from StockTick#time(2 sec) match_recognize...

文档链接为http://espertech.com/esper/release-6.1.0/esper-reference/html_single/index.html#match-recognize-datawindow