CUSTOM

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

This page discusses:

See Also
Operators
Expression Language
Defining and Managing Data Queries

Configuration

This aggregator uses n variables. These variables are updated through expressions that are executed for every element entering the operator.

When the input stream is fully consumed, Apollo executes the output expression to create the single value that goes out of the operator.

This expression can access all variables.

By default, this operator operates in sequential mode (see the configuration below), keeping the element order from the stream.

This code sample shows the operator configuration:

var element;

var var1 = ...// default value

var var2 = ...// default value

var var3 = ...// default value

while((element = getNextValue()) != null && $termination_expression == false) {

  var1 = ... //update var

  var2 = ... //update var

  var3 = ... //update var

}

return $output_expression;  

There are 3 phases:

  1. Initialization of the variables.
  2. Iteration over the stream while updating the variables for each element.
  3. Output a value using the final values of the variables.
Note: You can use a termination expression 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