2

I have the below query in Siddhi (WSO2 Stream Processor) where I am trying to get the final sum by county when I send stream of 10 events (4 events for ABC, 6 events for CDE). But, with the below query I get all the 10 records with sum of the previous event in the table (total I see 10 records in the table).

My expected output should be as below:

ABC 13456 34521
CDE 23789 65342

Please help me to get the final entry in the table instead all the 10 entries.

Siddhi Query:

partition with (county of TIVStream ) 
begin     
from TIVStream     
select county, sum(tiv_2011) as Sum2011 , sum(tiv_2012) as Sum2012    
insert events into TIV  
end; 

Thank you, Divya

4

1 回答 1

1

您上面需要的是某种收集事件的窗口。在 siddhi 中有多种窗口类型,主要分为两种,即长度窗口和时间窗口。对于上述用例,它应该是一个批处理窗口,您可以使用 timeBatch。有关文档,请参阅 [1]。

尝试以下,

partition with (county of TIVStream ) 
begin     
   from TIVStream#window.timeBatch(5 sec)     
   select county, sum(tiv_2011) as Sum2011 , sum(tiv_2012) as Sum2012    
   insert events into TIV  
end; 

以上将假设所有 10 个事件都在 5 秒内到达。

[1] https://wso2.github.io/siddhi/documentation/siddhi-4.0/#partition

于 2018-03-02T20:21:00.920 回答