Reducer functions
A reducer function aggregates multiple values of a non-ID attribute into one attribute value of a single vertex or edge. Reducer functions are computed incrementally; that is, each time a new input token is applied, a new resulting value is computed.
Syntax
To reduce and load aggregate data to an attribute, the attribute expression has the following form:
REDUCE(reducer_function (input_expr))
reducer_function
is one of the functions in the following table.
input_expr
can include non-reducer functions, but reducer functions cannot be nested.
Each reducer function can be used for several data types:
-
For primitive data types, the output type is the same as the type of the input expression
input_expr
. -
For
LIST
,SET
, andMAP
containers, theinput_expr
type is one of the allowed element types for these containers. The output is the entire container.
Table of reducer functions
Function name | Return value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
Any: If an attribute value already exists, return(retain) the existing value.
Otherwise, return (load) |
Each function supports a certain set of attribute types.
Calling a reducer function with an incompatible type causes the loading job to fail.
In order to prevent this, use the WHERE
clause together with IS NUMERIC
or other operators, functions, predicates for type checking if necessary.