简体   繁体   中英

wso2 cep - SiddhiQL - sum different rows from the same event table

I have one event table called eventCount and has the following values:

ID  |   eventCount
1            3
2            1
3            5
4            1

I have a stream of data coming in where I count the values of a certain type for a time period (1 second) and depending on the type and time period I will count() and write the value of the count() in the correspondent row.

I need to make a sum of the values within the event table.

I tried to create another event table and join both. Although I am getting the error of you cannot join from 2 static sources.

What is the correct way of doing this from SIddiQL in WSO2 CEP

In your scenario, Sum of the values in the event table is equivalent to the total number of events, doesn't it? So why you need to keep it an event table, can't you just it then and there (like below)?

@Import('dataIn:1.0.0')
define stream dataIn (id int);

@Export('totalCountStream:1.0.0')
define stream totalCountStream (eventCount long);

@Export('perIdCountStream:1.0.0')
define stream perIdCountStream (id int, eventCount long);

partition with (id of dataIn)
begin
    from dataIn#window.time(5 sec)
    select id, count() as eventCount
    insert into perIdCountStream;
end;

from dataIn#window.time(5 sec)
select count() as eventCount
insert into totalCountStream;

ps: if you really need the event tables, you can always persist totalCountStream and perIdCountStream in two separate tables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM