Developing Apama Applications > EPL Reference > Aggregate Functions > Built-in aggregate functions
Built-in aggregate functions
EPL provides the following built-in aggregate functions. In the table, the argument names, for example, value and weight, are placeholders for expressions. Additional information about some of these functions follows the table.
Aggregate Function
Argument(s)
Returns
Result Description
avg(value)
decimal or float
decimal or float
The arithmetic mean of the values in the window. The avg() and mean() functions do exactly the same thing. They are aliases for each other.
count()
-
integer
The number of items in the window, including any NaN items.
count (predicate)
boolean
integer
The number of items for which the argument is true.
count(value)
decimal or float
integer
The number of items where the decimal or float value is not NaN.
first(value)
decimal or float
decimal or float
The earliest value in the window being aggregated over.
last(value)
decimal or float
decimal or float
The latest value in the window being aggregated over.
max(value)
decimal or float
decimal or float
The maximum value.
mean(value)
decimal or float
decimal or float
The arithmetic mean of the values in the window. The mean() and avg() functions do exactly the same thing. They are aliases for each other.
min(value)
decimal or float
decimal or float
The minimum value.
nth(value,index) nth(value,0) returns the same item as first(value).
decimal, integer or float, integer
decimal or float
The value of the specified decimal or float item in the index position, starting with the earliest item in the window (item 0) and moving toward the latest item.
prior(value,index) prior(value,0) returns the same item as last(value).
decimal, integer or float, integer
decimal or float
The value of the specified decimal or float item in the index position, starting with the most recent item in the window (item 0 ) and moving toward the earliest item.
stddev(value)
decimal or float
decimal or float
The standard deviation of the values.
stddev2(value)
decimal or float
decimal or float
The sample standard deviation of the values.
sum(value)
decimal, float or integer
decimal, float or integer
The sum of the values.
wavg(value,weight)
decimal,decimal or float,float
decimal or float
The weighted average of the values where each value is weighted by the corresponding weight.
Calculations by the built-in aggregate functions might be affected by underflow and overflow. For example, adding a very large number to the collection that the sum() function operates on, then adding a very small number, and then removing the very large number will probably result in 0, and not the very small number. Just adding the very small number would result in behavior that you would expect. The overflow and underflow characteristics are as defined for IEEE 64-bit floating point numbers.
Positional functions
For the first(), last(), nth(), and prior() functions, all values (NaN, +-∞ and so on) are treated the same, and position in the window is the only thing that matters.
Overloaded functions
The sum() function is overloaded. You can specify a decimal, float or integer. The return type matches the argument type.
The avg(), first(), last(), max(), mean(), min(), nth(), prior(), stddev(), and stddev2() functions are overloaded. You can specify a decimal or a float. The return type matches the argument type.
The count() function is overloaded. You can specify a boolean , decimal, float or no argument. The return type is an integer.
The wavg()function is overloaded. You can specify a decimal, decimal or a float, float combination. The return type will be a decimal or a float, respectively.
See also:
Select clause for information about the select clause in Apama queries
Working with Streams and Stream Queries
Aggregating items in projections
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.