Defining global event aggregates
You define a global event aggregate by specifying an aggregate expression, an optional time filter, and an optional default value.
Before you begin
Create a global aggregate definition file (.agg).
About this task
A global event aggregate can find the total, minimum, maximum, or average value of a collection of events, or the number of events. For example, if your events are flight departures, you can determine the average number of delayed flight departures over the past month or another time period.
Global event aggregates run continuously as part of a deployed solution. A global event aggregate is calculated every time one of the events occurs.
define '<same_name_as_file>' as <expr>
If events have occurred for too short a time, a global event aggregate might not have a meaningful value. Therefore, you can specify a default value and the condition for when the default applies. The default value applies unless enough event history exists for the aggregate calculations, and any rules that are based on them, to have meaningful results. You might need to test and experiment with the default value and the condition to obtain optimal results for your particular solution.
The event history is the elapsed time after the first event of any type occurs in a deployed solution. If you change the definition of the global event aggregate and deploy a new version of the solution, the elapsed time is reset to zero and restarts after the first event of any type occurs.
In the editor, you can type Space or Ctrl+Space to display the available constructs, and then double-click a construct to select it.
Procedure
Results
The global aggregate is verbalized and you can use its variable name in rules and Java™ agents in your solution. In a Java agent and in the REST API, you must prefix defvar to the variable name.
Examples
define 'average_delay' as the average delay of all flight_delay events
This statement defines the global aggregate variable average_delay, which can be used in the rules in the solution. When the solution is deployed and running, partitions in the data grid receive flight_delay events, and a local average is calculated within each partition, relating to the delays at the particular entity, such as an airport. The partial results are aggregated to obtain the overall average delay.
define 'average_delay' as the average delay of all flight_delay events, where the delay of each flight_delay event is more than 10
The condition restricts the calculation to only the delays that are more than 10 minutes.
define 'average_delay' as the average delay of all flight_delay events, where the delay is more than 10
define 'average_delay' as the average delay of all flight_delay events, defaulting to 5 if there is less than 2 hours of event history