sumMap
Totals one or more value
arrays according to the keys specified in the key
array. Returns a tuple of arrays: keys in sorted order, followed by values summed for the corresponding keys without overflow.
Syntax
sumMap(key <Array>, value1 <Array>[, value2 <Array>, ...])
Array type.sumMap(Tuple(key <Array>[, value1 <Array>, value2 <Array>, ...]))
Tuple type.
Alias: sumMappedArrays
.
Arguments
Passing a tuple of key and value arrays is a synonym to passing separately an array of keys and arrays of values.
The number of elements in key
and all value
arrays must be the same for each row that is totaled.
Returned Value
- Returns a tuple of arrays: the first array contains keys in sorted order, followed by arrays containing values summed for the corresponding keys.
Example
First we create a table called sum_map
, and insert some data into it. Arrays of keys and values are stored separately as a column called statusMap
of Nested type, and together as a column called statusMapTuple
of tuple type to illustrate the use of the two different syntaxes of this function described above.
Query:
Next, we query the table using the sumMap
function, making use of both array and tuple type syntaxes:
Query:
Result:
Example with Multiple Value Arrays
sumMap
also supports aggregating multiple value arrays simultaneously.
This is useful when you have related metrics that share the same keys.
In this example:
- The result tuple contains three arrays
- First array: keys (browser names) in sorted order
- Second array: total impressions for each browser
- Third array: total clicks for each browser
See Also