I am trying to write a simple siddhi query which detects a pattern eg: "Ice" "cream" "x" "y" "apple" "water"
where events Ice & cream both should be together and apple water should be together and x y are any random values in the window.length(6)
problem is the following query is not restricting the window.length(6) how can i achieve this?
from every (( s1=windowedStream[s1.val=='ice']-> s2= windowedStream[s2.val=='cream'] )
-> ( a1=windowedStream[a1.val=='apple'] -> a2 = windowedStream[a2.val =='water'] ))
select s1.meta_timestamp, s1.val
insert into filteredStream
As per the existent notations, Siddhi allows you to restrict a pattern based on a time window only. Please refer the following.
https://docs.wso2.com/display/CEP420/SiddhiQL+Guide+3.1#SiddhiQLGuide3.1-Pattern
As a workaround to restricting the patterns based on a length window, you may introduce a 3rd attribute called index to the "windowedStream", where index reflects the order of event arrival (i.e. index of the 1st event is 1, index of the 2nd event is 2 and so on). Then the following query would capture the patterns occurring within a length window of 6 events.
from every (( s1=tempStream[s1.val=='ice']-> s2= tempStream[s2.val=='cream'] )
-> ( a1=tempStream[a1.val=='apple'] -> a2 = tempStream[a2.val =='water' and a2.index- s1.index <= 6]))
select s1.meta_timestamp, s1.val
insert into filteredStream;
Hope this helps.