Aggregate Array | ARRAY_AGGREGATE

Syntax

ARRAY_AGGREGATE( [value], [aggregation] )

Parameters

value
The ARRAY being aggregated. It should be an ARRAY of MAP / OBJECT records.

aggregation
A MAP that defines how the VALUE is to be aggregated. Each key in the MAP should be a path into the entries in the VALUE array. Each value in the map must be an aggregation operator. The valid operators are as follows:

Return Value

A single MAP / OBJECT with the results of the aggregation performed on the VALUE.

Description

Reduce an ARRAY of OBJECT / MAP records into a single OBJECT according to a provided aggregation operation.

Examples

# VALUE is [["a" => 1, "b" => 2], ["a" => 3, "b" => 4], ["a" => 5, "b" => 6]]
ARRAY_AGGREGATE(VALUE, ["a" => "sum", "b" => "average"]) # returns ["a" => 9, "b" => 4]
# VALUE is [["a" => 1, "b" => 2], ["a" => 3, "b" => 4], ["a" => 5, "b" => 6]]
ARRAY_AGGREGATE(VALUE, ["a" => "first", "b" => "last"]) # returns ["a" => 1, "b" => 6]
# VALUE is [["a" => 1, "b" => 2], ["a" => 3, "b" => 4], ["a" => 5, "b" => 6]]
ARRAY_AGGREGATE(VALUE, ["a" => "max", "b" => "min"]) # returns ["a" => 5, "b" => 2]
# VALUE is [["a" => 1, "b" => 2], ["a" => 3, "b" => 4], ["a" => 5, "b" => 6]]
ARRAY_AGGREGATE(VALUE, ["a" => "push"]) # returns ["a" => [1, 3, 5]]
# VALUE is [["a" => ["b" => 1]], ["a" => ["b" => 4]], ["a" => ["b" => 10]]]
ARRAY_AGGREGATE(VALUE, ["a.b" => "average"]) # returns ["a" => ["b" => 5]]