windowaggregationsiddhi

How create a siddhi app with Multiple conditional count


I have a special situation and I can not implement it with siddhi options like window, pattern or aggregation functions. The data comes from 2 streams, I set the source in both streams of KAFKA and I set the list of topics in siddhi source p1, p2. I wrote a query for checks 2 rules (type = "h") and (type = "g"). The siddhi app must only allows events to match these conditions. I need to aggregate every 10 seconds, when the number of events that match the first condition is 2 and the number of events that match the second condition is 5 at this time. How?


Solution

  • Finally found the solution:

    from stream1#window.time(10 seconds)
    select type, id, sum(ifThenElse(type == 'h', 1, 0)) as cnt1,   sum(ifThenElse(type == 'g', 1, 0)) as cnt2
        having cnt1 == 2 and cnt2 == 5
    insert all events into stream2;
    

    I tested this code manytimes with many values(0, 1, 2, ...) that passed all of them.