MAP_AGG Function
Description
The MAP_AGG function aggregates key-value pairs into a MAP data structure. It collects all key-value pairs and combines them into a Map, where each key corresponds to a value.
Parameters
key: An expression of any comparable primitive type, used as the Map key.NULLkeys are ignored.- For duplicate keys, the first occurring value is retained.
value: An expression of any type, used as the Map value.valuecan beNULL.
Return Type
- Returns
map<key_type, value_type>type (non-null). - Returns a Map containing all key-value pairs.
Notes
- If all
keyvalues areNULL, an empty Map{}is returned. - If the input is an empty set, an empty Map
{}is returned. - The order of keys in the Map is non-deterministic; do not rely on ordering.
- Behavior for duplicate keys may vary by implementation; avoid using duplicate keys where possible.
Examples
- Basic usage: aggregate key-value pairs into a Map
- NULL keys are ignored
- Duplicate keys: the first value is retained
- All keys are NULL: returns an empty Map
