Aggregate functions are used to perform operations such as sum on aggregated set of events through a window. Usage of an aggregate function is as follows.
@info(name = 'query1')
from cseEventStream#window.timeBatch(1 sec)
select symbol, sum(price) as price
insert into resultStream;
Following are the supported inbuilt aggregate functions of Siddhi.
Sum
Syntax  <longdouble> sum(<intlongdoublefloat> arg) 

Extension Type  Aggregate Function 

Description  Calculates the sum for all the events. 

Parameter  The value that needs to be summed. 

Return Type  Returns long if the input parameter type is int or long , and returns double if the input parameter type is float or double. 

Examples  sum(20 ) returns the sum of 20s as a long value for each event arrival and expiry. sum(temp) returns the sum of all temp attributes based on each event arrival and expiry.


Average
Syntax  <double> avg(<intlongdoublefloat> arg) 

Extension Type  Aggregate Function 

Description  Calculates the average for all the events. 

Parameter  arg : The value that need to be averaged. 

Return Type  Returns the calculated average value as a double. 

Example  avg(temp) returns the average temp value for all the events based on their arrival and expiry. 

Maximum
Syntax  <intlongdoublefloat> max(<intlongdoublefloat> arg) 

Extension Type  Aggregate Function 

Description  Returns the maximum value for all the events. 

Parameter  arg : The value that needs to be compared to find the maximum value. 

Return Type  Returns the maximum value in the same data type as the input. 

Example  max(temp) returns the maximum temp value recorded for all the events based on their arrival and expiry. 

Minimum
Syntax  <intlongdoublefloat> min(<intlongdoublefloat> arg) 

Extension Type  Aggregate Function 

Description  Returns the minimum value for all the events. 

Parameter  arg : The value that needs to be compared to find the minimum value. 

Return Type  Returns the minimum value in the same type as the input. 

Example  min(temp) returns the minimum temp value recorded for all the events based on their arrival and expiry. 

Count
Syntax  <long> count() 

Extension Type  Aggregate Function 

Description  Returns the count of all the events. 

Return Type  Returns the event count as a long. 

Example  count() returns the count of all the events. 

Standard Deviation
Syntax  <double> stddev(<intlongdoublefloat> arg) 

Extension Type  Aggregate Function 

Description  Returns the calculated standard deviation for all the events. 

Parameter  arg : The value that should be used to calculate the standard deviation. 

Return Type  Returns the calculated standard deviation value as a double. 

Example  stddev(temp) returns the calculated standard deviation of temp for all the events based on their arrival and expiry. 

Distinct Count
Syntax  <long> distinctcount(<intlongdoublefloatstring> arg) 

Extension Type  Aggregate Function 

Description  Returns the count of distinct occurrences for a given arg. 

Parameter  arg : The value that should be counted. 

Return Type  Returns the count of distinct occurances for a given arg. 

Example  distinctcount(pageID) for the following output returns 3 .
"WEB_PAGE_1" "WEB_PAGE_1" "WEB_PAGE_2" "WEB_PAGE_3" "WEB_PAGE_1" "WEB_PAGE_2"


Forever Maximum
Syntax  <intlongdoublefloat> maxForever (<intlongdoublefloat> arg) 

Extension Type  Aggregate Function 

Description  This is the attribute aggregator to store the maximum value for a given attribute throughout the lifetime of the query regardless of any windows infront. 

Parameter  arg : The value that needs to be compared to find the maximum value. 

Return Type  Returns the maximum value in the same data type as the input. 

Example  maxForever(temp) returns the maximum temp value recorded for all the events throughout the lifetime of the query. 

Forever Minimum
Syntax  <intlongdoublefloat> minForever (<intlongdoublefloat> arg) 

Extension Type  Aggregate Function 

Description  This is the attribute aggregator to store the minimum value for a given attribute throughout the lifetime of the query regardless of any windows infront. 

Parameter  arg : The value that needs to be compared to find the minimum value. 

Return Type  Returns the minimum value in the same data type as the input. 

Example  minForever(temp) returns the minimum temp value recorded for all the events throughout the lifetime of the query. 
