0

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

Community
  • 1
  • 1

1 Answers1

0

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.

Grainier
  • 1,634
  • 2
  • 17
  • 30
  • the problem is that i not only have sum of events, but i also have percentages. and i really need the table. – JoaoFilipeClementeMartins Feb 13 '17 at 09:05
  • If you need the percentage, you can still join perIdCountStream with totalCountStream and calculate. Otherwise, you might have to write a custom Stream Processor Extension to calculate and emit all the aggregated values. Since you are aggregating & storing values for a certain time period (1 sec), I don't think you'll be needing event tables. – Grainier Feb 13 '17 at 15:05