2010-01-26 75 views
3

我有一個非實時Esper配置,其中我提供了一個從文件中讀取的流。我試圖創建一個表達式來計算整個流的統計量並在最後輸出一個值。例如,Esper具有強制視圖每隔X秒輸出一次的語義,但是在知道沒有更多事件需要輸入時,請求視圖或引擎「刷新」輸出的語義是否有語義。在Esper中強制輸出

回答

8

原來,至少有一種方法是使用帶有變量觸發器的輸出子句。

的表達應該是:

select count(*) as totalCount from events output last when OutputSummary = true 

的OutputSummary變量將被初始化像這樣:

epConfiguration.addVariable("OutputSummary", Boolean.class, "false"); 

當你準備好沖洗,變量設置爲true,像這樣:

epRuntime.setVariableValue("OutputSummary", true); 
long currentTime = epService.getEPRuntime().getCurrentTime(); 
epRuntime.sendEvent(new CurrentTimeEvent(currentTime)); 

有必要發送另一個時間事件來強制表達式進行評估。

0

當輸出需要在每60秒,則表達式將是:

select emplyee_id from employees output snapshot every 60 sec 

並且當所述輸出需要在每10000個事件,則表達式將是:

select emplyee_id from employees output snapshot every 10000 events