1

How can I define a Siddhi query to detect two events e1 and e2 with the following properties:

  • e1 may occurs before or after e2.
  • This means: abs( e1.timestamp - e2.timestamp ) <= 5s)

In Drools we can use the Allen operator coincides: e1 coincides e2[5s]

Community
  • 1
  • 1
essafihm
  • 11
  • 1

1 Answers1

0

if both e1 and e2 are two different type of events from the same stream then

from every e1=FooStream -> e2=FooStream[e1.type!= e2.type and math:abs(e1.timestamp - e2.timestamp ) <= 5*6000] 
within 10 sec
select e1.timestamp, e2. ...
insert into OutputStream;

else if they are from different streams, you might need to write two queries

from every e1=FooStream -> e2=BarStream[math:abs( e1.timestamp - e2.timestamp ) <= 5*6000] 
within 10 sec
select e1.timestamp, e2. ...
insert into OutputStream; 

from every e1=BarStream -> e2=FooStream[math:abs( e1.timestamp - e2.timestamp ) <= 5*6000] 
within 10 sec
select e1.timestamp, e2. ...
insert into OutputStream; 

If "timestamp" is a Siddhi event timestamp (not a attribute in event) then we can just use "within 5 sec" and omit the filter clauses, but if timeStamp is also sent as a ordinary attribute then we have to follow the above query formats.

suho
  • 912
  • 6
  • 12
  • Thanks for the reply. It works now but I don't understand the multiplication by 6000! can you make it clear to me why? – essafihm Jan 17 '16 at 18:15