Sri
Sri

Reputation: 105

wso2 CEP :: Aggregate functions in "select" clause error

I'm trying to write an Execution Plan in wso2's CEP. But I'm getting an error in the select clause if I use the aggregated functions. In my case it is "sum". Please read below for further details:


@Export('stream.sla.consolidated.breach:1.0.0')
define stream ConsolidatedBreachSLA (breach_date string, breach_count_per_day int,request_id int);

@Export('stream.sla.breach.details:1.0.0')
define stream BreachSLA (request_id int, breach_date string, breach_flag int);

from BreachSLA#window.length(50)
select breach_date as breach_date,sum(breach_flag) as breach_count_per_day,request_id
group by breach_date
having breach_count_per_day > 2
insert into ConsolidatedBreachSLA;

CEP Error


But as soon as I remove the "sum" from select clause everything seems to get validated correctly.

from BreachSLA#window.length(50)
select breach_date as breach_date,breach_flag as breach_count_per_day,request_id
group by breach_date
having sum(breach_count_per_day) > 2
insert into ConsolidatedBreachSLA;

The intent is to get the sum of records in the select clause such that the value of the sum could be exported to a publisher.

Upvotes: 1

Views: 65

Answers (2)

Sri
Sri

Reputation: 105

Rajeev was right about the conflict.

I was trying different things with this problem and I tried the "convert" function and it helped.

So I changed my Siddhi query to

from BreachSLA#window.length(50) select breach_date,convert(sum(breach_flag),'int') as breach_count_per_day group by breach_date having breach_count_per_day > 2 insert into BreachCountDay;

Upvotes: 1

Rajeev Sampath
Rajeev Sampath

Reputation: 2757

The sum function returns a long value (for int or long inputs) whereas your attribute 'breach_flag' is defined as an int. It seems the stream is already defined with an int attribute for this, hence this conflict occurs and you'll need to modify the defined stream's (ConsolidatedBreachSLA and any subsequent streams) attribute type (i.e. type of breach_count_per_day) to 'long' to get the sum.

Upvotes: 1

Related Questions