Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Aggregate functions are used to perform operations such as sum on aggregated set of events through a window. Usage of a 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<long|double> sum(<int|long|double|float> arg)
Extension TypeAggregate Function
DescriptionCalculates the sum for all the events.
ParameterThe value that needs to be summed.
Return TypeReturns 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(<int|long|double|float> arg)
Extension TypeAggregate Function
DescriptionCalculates the average for all the events.
Parameterarg: The value that need to be averaged.
Return TypeReturns the calculated average value as a double.
Exampleavg(temp) returns the average temp value for all the events based on their arrival and expiry.

Maximum

Syntax<int|long|double|float> max(<int|long|double|float> arg)
Extension TypeAggregate Function
DescriptionReturns the maximum value for all the events.
Parameterarg: The value that needs to be compared to find the maximum value.
Return TypeReturns the maximum value in the same data type as the input.
Examplemax(temp) returns the maximum temp value recorded for all the events based on their arrival and expiry.

Minimum  

Syntax<int|long|double|float> min(<int|long|double|float> arg)
Extension TypeAggregate Function
DescriptionReturns the minimum value for all the events.
Parameterarg: The value that needs to be compared to find the minimum value.
Return TypeReturns the minimum value in the same type as the input.
Examplemin(temp) returns the minimum temp value recorded for all the events based on their arrival and expiry.

Count

Syntax<long> count()
Extension TypeAggregate Function
DescriptionReturns the count of all the events.
Return TypeReturns the event count as a long.
Examplecount() returns the count of all the events.

Standard Deviation

Syntax<double> stddev(<int|long|double|float> arg)
Extension TypeAggregate Function
DescriptionReturns the calculated standard deviation for all the events.
Parameterarg: The value that should be used to calculate the standard deviation.
Return TypeReturns the calculated standard deviation value as a double.
Examplestddev(temp) returns the calculated standard deviation of temp for all the events based on their arrival and expiry.

Distinct Count

Syntax<long> distinctcount(<int|long|double|float|string> arg)
Extension TypeAggregate Function
DescriptionAggregate function to returns the count of distinct occurances of a given arg
Parameterarg: The value that should be counted
Return TypeReturns the count of distinct occurances of given arg
Example

distinctcount(pageID) for following output will return 3.
 "WEB_PAGE_1"
 "WEB_PAGE_1"
 "WEB_PAGE_2"
 "WEB_PAGE_3"
 "WEB_PAGE_1"
 "WEB_PAGE_2"

Forever Maximum

Syntax<int|long|double|float> maxForever (<int|long|double|float> arg)
Extension TypeAggregate Function
DescriptionAttribute aggregator to store maximum value for a given attribute throughout the lifetime of the query regardless of any windows in-front.
Parameterarg: The value that needs to be compared to find the maximum value.
Return TypeReturns the maximum value in the same data type as the input.
ExamplemaxForever(temp) returns the maximum temp value recorded for all the events throughout the lifetime of query

Forever Minimum

Syntax<int|long|double|float> minForever (<int|long|double|float> arg)
Extension TypeAggregate Function
DescriptionAttribute aggregator to store minimum value for a given attribute throughout the lifetime of the query regardless of any windows in-front.
Parameterarg: The value that needs to be compared to find the minimum value.
Return TypeReturns the minimum value in the same data type as the input.
ExampleminForever(temp) returns the minimum temp value recorded for all the events throughout the lifetime of query

  • No labels