CUSTOM

The CUSTOM aggregation function takes a stream as input and returns a single value. The value type depends on the configuration.

This page discusses:

See Also
RESULT SET
AGGREGATE
GROUP BY
Choose Where to Apply Aggregations

Configuration

This aggregator follows 3 phases:

  1. It initializes variables.
  2. It iterates over the stream while updating the variables for each element.
  3. It returns an output expression value using the final values of the variables.
Parameter Description
Filter expressionAn expression to keep some elements only. It is useful to process the aggregation on a subpart of your input stream.
Variables This aggregator uses n variables. These variables are updated through expressions that are executed for every element entering the operator.
Updates Defines how to iterate with Variables on specific objects.
Output expression

When the input stream is fully consumed, the output expression creates the single value that goes out of the operator.

This expression can access all variables.

By default, this operator operates in sequential mode, keeping the element order from the stream.

Terminal condition You can use a terminal condition to stop the iteration on the stream (phase 2) and directly go to the output phase (phase 3).

Input

There is one Input. There are no constraints on the element type or on the number of elements in the stream.

Output

There must be one Output. As an aggregator, this function emits a single value. The type of this value depends on the configuration (Output expression).

Example: Computing a Standard Deviation

Let us assume that the average of the values of the stream is already computed and stored in a global @avg variable.

In this example, the input stream is a stream of Integer.

  1. Declare 2 variables:
    count, type : Integer, default value : 0
    sum_squared_diff, type : Float, default value : 0.0
  2. Update the 2 variables:
    count = count + 1
    sum_squared_diff = sum_squared_diff + Math.pow(val-@avg, 2)

    Where: val is the element coming from the stream.

  3. Declare the output expression:
    sum_squared_diff / count