2017-04-05 25 views
0

從下面的流中,我想要警告在溫度超過90°時發生兩次的事件(如每次2個事件的溫度> 90需要被警告)。WSO2 CEP:Siddhi QL:如何在匹配某些條件後始終如一地警告事件

InputStream=[1001,91] 
InputStream=[1001,86] 
InputStream=[1002,70] 
InputStream=[1001,85] 
InputStream=[1003,70] 
InputStream=[1003,85] 
InputStream=[1002,70] 
InputStream=[1003,70] 
InputStream=[1003,87] 
InputStream=[1002,70] 
InputStream=[1001,95] 
InputStream=[1001,96] 
InputStream=[1001,97] 
InputStream=[1001,98] 
InputStream=[1001,98] 

我寫了這樣的事情:

@Plan:name('TestExecutionPlan') 

define stream InputStream (id string, temp int); 

partition with (id of InputStream) 
begin 
from InputStream 
select id, temp 
having temp > 90 
insert into CriticalStream 
end; 

from CriticalStream[count(id) == 2] 
select id, temp 
group by id 
--having count(id) == 2 
insert into EventReporter; 

但其警告僅1 EventReporter流中的事件。

Below is the screen shot from Try It

我期待的EventReporter流具有[1001,97]和[1001,98]還有,現在它只有在[1001,95]記錄。有人能指出我在這裏做錯了嗎?如何在分組之後循環處理事件?我嘗試添加window.time和window.length,但沒有得到所需的輸出。任何幫助/指導將非常感激。謝謝。

回答

1

你不需要在那裏分區。你可以簡單地使用一個過濾器和一個lengthBatch窗口來獲得你想要的輸出。嘗試下面的執行計劃;

@Plan:name('ExecutionPlan') 

@Import('InputStream:1.0.0') 
define stream InputStream (id string, temp int); 

/* Filter events with temp > 90 */ 
from InputStream[temp > 90] 
insert into CriticalStream; 

/* Aggregate within a lengthBatch window, while group by id*/ 
from CriticalStream#window.lengthBatch(2) 
select id, temp, count() as count 
group by id 
insert into EventReporter; 

/* Just for logging the result in the cosole */ 
from EventReporter#log("Logging EventReporter : ") 
insert into #temp; 
+0

嗨Grainier,該解決方案工作。非常感謝你的時間和幫助。 – Kannan

+0

Grainier,我在這裏有另一個問題:http://stackoverflow.com/questions/43186895/wso2-cep-siddhi-ql-creating-a-unique-stream-with-similar-event-records 真的很感激,如果你可以看看它並給出寶貴的意見。謝謝。 – Kannan

相關問題