Siddhi 查询具有条件的顺序事件

Siddhi query for sequential events with conditions

我正在尝试编写一个查询(不确定是否可行),形式为 "If a person has value X their next value cannot be value Y for the next 5 seconds"

我的两次尝试是:

顺序:

define stream inStream(person string, value string); 
            from every s1=inStream[value == 'X'],  
            s2=inStream[person == s1.person and value == 'Y'] within 5 sec  
            select s2.person  
            insert into outStream

这适用于简单的情况,但如果我提供如下输入:

"bob", "X"
"steve", "ABC"
"bob", "Y"

然后规则永远不会为 Bob 触发,因为中间有一个来自 Steve 的事件。

如果我像这样尝试这个模式:

define stream inStream(person string, value string); 
            from every s1=inStream[value == 'X']  
            -> s2=inStream[person == s1.person and value == 'Y'] within 5 sec  
            select s2.person  
            insert into outStream

然后在以下情况下失败:

"bob", "X"
"bob", "Z"
"bob", "Y"

因为在 5 秒内 Y 仍然在 X 之后,即使两者之间有一个值。

我的问题是,是否有一种方法可以使用条件进行顺序查询(例如,仅针对同一个人进行顺序查询)或一种带有某种检查的模式,以了解是否在 X 和 Y 之间收到了另一个值?

最终对我有用的解决方案是使用带分区的顺序方法:

define stream inStream(person string, value string);  
            partition with (person of inStream)  
            begin  
            from every s1=inStream[value == 'X'],  
            s2=inStream[value == 'Y'] within 5 sec  
            select s2.person  
            insert into outStream  
            end