divya
divya

Reputation: 21

Consolidated output in table with Siddhi WSO2 stream processor

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

Upvotes: 2

Views: 172

Answers (1)

dnWick
dnWick

Reputation: 393

What you need above is a some sort of window to collect events. In siddhi there are various window types mainly categorize in to two, namely length and time windows. For above usecase it should be a batch window and you can use a timeBatch. Please see[1] for docs.

Try following ,

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; 

Above will assume all the 10 events are arriving within 5 sec of time.

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

Upvotes: 1

Related Questions