Skip to content

map

Functions for working with arrays of key/value structs.

extract_keyed_scalar_sum (UDF)

Sums all values in a keyed scalar.

Extract Keyed Scalar Sum

Takes a keyed scalar and returns a single number: the sum of all values it contains. The expected input type is ARRAY<STRUCT<key STRING, value INT64>>

The return type is INT64.

The key field will be ignored.

Parameters

INPUTS

keyed_scalar ARRAY<STRUCT<key STRING, value INT64>>

OUTPUTS

INT64

Source | Edit

from_lists (UDF)

Create a map from two arrays (like zipping)

Parameters

INPUTS

keys ANY TYPE, `values` ANY TYPE

OUTPUTS

ARRAY<STRUCT<key STRING, value STRING>>

Source | Edit

get_key (UDF)

Fetch the value associated with a given key from an array of key/value structs.

Because map types aren't available in BigQuery, we model maps as arrays of structs instead, and this function provides map-like access to such fields.

Parameters

INPUTS

map ANY TYPE, k ANY TYPE

Source | Edit

get_key_with_null (UDF)

Fetch the value associated with a given key from an array of key/value structs.

Because map types aren't available in BigQuery, we model maps as arrays of structs instead, and this function provides map-like access to such fields. This version matches NULL keys as well.

Parameters

INPUTS

map ANY TYPE, k ANY TYPE

OUTPUTS

STRING

Source | Edit

mode_last (UDF)

Combine entries from multiple maps, determine the value for each key using mozfun.stats.mode_last.

Parameters

INPUTS

entries ANY TYPE

Source | Edit

set_key (UDF)

Set a key to a value in a map. If you call map.get_key after setting, the value you set will be returned.

map.set_key

Set a key to a specific value in a map. We represent maps as Arrays of Key/Value structs: ARRAY<STRUCT<key ANY TYPE, value ANY TYPE>>.

The type of the key and value you are setting must match the types in the map itself.

Parameters

INPUTS

map ANY TYPE, new_key ANY TYPE, new_value ANY TYPE

OUTPUTS

STRING

Source | Edit

sum (UDF)

Return the sum of values by key in an array of map entries. The expected schema for entries is ARRAY>, where the type for value must be supported by SUM, which allows numeric data types INT64, NUMERIC, and FLOAT64.

Parameters

INPUTS

entries ANY TYPE

Source | Edit