Map functions and operators
Subscript operator: []
The []
operator is used to retrieve the value corresponding to a given
key from a map:
Map functions
cardinality()
cardinality(x)
→ bigint
Returns the cardinality (size) of the map x
.
element_at()
element_at(map(K,V), key)
→ V
Returns value for given key
, or NULL
if the key is not contained in
the map.
map()
map()
→ map(unknown, unknown)
Returns an empty map:
map(array(K), array(V))
→ map(K,V)
Returns a map created using the given key/value arrays:
See also map_agg
and multimap_agg
for creating a map as an aggregation.
map_from_entries()
map_from_entries(array(row(K,V)))
→ map(K,V)
Returns a map created from the given array of entries:
multimap_from_entries()
multimap_from_entries(array(row(K,V)))
→ map(K,array(V))
Returns a multimap created from the given array of entries. Each key can be associated with multiple values:
map_entries()
map_entries(map(K,V))
→ array(row(K,V))
Returns an array of all entries in the given map:
map_concat()
map_concat(map1(K,V), map2(K,V), ..., mapN(K,V))
→ map(K,V)
Returns the union of all the given maps. If a key is found in multiple given maps, that key’s value in the resulting map comes from the last one of those maps.
map_filter()
map_filter(map(K,V), function(K,V,boolean))
→ map(K,V)
Constructs a map from those entries of map
for which function
returns true:
map_keys()
map_keys(x(K,V))
→ array(K)
Returns all the keys in the map x
.
map_values()
map_values(x(K,V))
→ array(V)
Returns all the values in the map x
.
map_zip_with()
map_zip_with(map(K,V1), map(K,V2), function(K,V1,V2,V3))
→ map(K,V3)
Merges the two given maps into a single map by applying function
to
the pair of values with the same key. For keys only presented in one
map, NULL will be passed as the value for the missing key:
transform_keys()
transform_keys(map(K1,V), function(K1,V,K2))
→ map(K2,V)
Returns a map that applies function
to each entry of map
and
transforms the keys:
transform_values()
transform_values(map(K,V1), function(K,V1,V2))
→ map(K,V2)
Returns a map that applies function
to each entry of map
and
transforms the values:
Was this page helpful?