Map functions

GoogleSQL for Bigtable supports the following map functions.

Function list

NameSummary
MAP_CONTAINS_KEYChecks if a key is in a map.
MAP_EMPTYChecks if a map is empty.
MAP_ENTRIESGets an array of key-value pairs from a map, sorted in ascending order by key.
MAP_KEYSGets an array of keys from a map, sorted in ascending order.
MAP_VALUESGets an array of values from a map, sorted in ascending order by key.

MAP_CONTAINS_KEY

MAP_CONTAINS_KEY(input_map,key_to_find)

Description

Checks if a key is in a map. ReturnsTRUE if the key is found. Otherwise,returnsFALSE.

Definitions

  • input_map: AMAP<K,V> value that represents the map to search.If this value isNULL, the function returnsNULL.
  • key_to_find: The key to find in the map.

Return type

BOOL

Examples

The following query checks if a column calledcell_plan in atable calledtest_table has a key calleddata_plan_05gb:

SELECTMAP_CONTAINS_KEY(cell_plan,b'data_plan_05gb')ASresultsFROMtest_table/*---------+ | results | +---------+ | TRUE    | | TRUE    | | FALSE   | | FALSE   | | FALSE   | +---------*/

MAP_EMPTY

MAP_EMPTY(input_map)

Description

Checks if a map is empty. ReturnsTRUE if the map is empty, otherwiseFALSE.

Definitions

  • input_map: AMAP<K,V> value that represents the map to search.If this value isNULL, the function returnsNULL.

Return type

BOOL

Example

The following query checks if a column calledcell_plan in a table calledtest_table is empty:

SELECTMAP_EMPTY(cell_plan)ASresultsFROMtest_table/*----------+ | results  | +----------+ | FALSE    | | FALSE    | | TRUE     | | TRUE     | | FALSE    | | FALSE    | +----------*/

MAP_ENTRIES

MAP_ENTRIES(input_map)

Description

Gets an array of key-value pairs from a map, sorted in ascending order by key.

Definitions

  • input_map: AMAP<K,V> value that represents the map to query.If this value isNULL, the function returnsNULL.

Return type

ARRAY<STRUCT<K,V>>

Examples

The following query gets key-value pairs, sorted in ascending order by key, froma table calledtest_table:

SELECTMAP_ENTRIES(cell_plan)ASresultsFROMtest_table/*-------------------------------------------------------------+ | results                                                     | +-------------------------------------------------------------+ | [ {"data_plan_01gb", "true"}, {"data_plan_05gb", "false"} ] | | [ {"data_plan_05gb", "false"} ]                             | | []                                                          | | [ {"data_plan_10gb", "false"} ]                             | | [ {"data_plan_10gb", "false"} ]                             | +-------------------------------------------------------------*/

MAP_KEYS

MAP_KEYS(input_map)

Description

Gets an array of keys from a map, sorted in ascending order.

Definitions

  • input_map: AMAP<K,V> value that represents the map to query.If this value isNULL, the function returnsNULL.

Return type

ARRAY<K>

Examples

The following query gets a list of keys, sorted in ascending order, from a tablecalledtest_table:

SELECTMAP_KEYS(cell_plan)ASresultsFROMtest_table/*----------------------------------------+ | results                                | +----------------------------------------+ | [ "data_plan_01gb", "data_plan_05gb" ] | | [ "data_plan_05gb" ]                   | | []                                     | | [ "data_plan_10gb" ]                   | | [ "data_plan_10gb" ]                   | +----------------------------------------*/

MAP_VALUES

MAP_VALUES(input_map)

Description

Gets an array of values from a map, sorted in ascending order by key.

Definitions

  • input_map: AMAP<K,V> value that represents the map to query.If this value isNULL, the function returnsNULL.

Return type

ARRAY<V>

Examples

The following query gets the values, sorted in ascending order by key, from atable calledtest_table:

SELECTMAP_VALUES(cell_plan)ASresultsFROMtest_table/*---------------------+ | results             | +---------------------+ | [ "true", "false" ] | | [ "false" ]         | | []                  | | [ "false" ]         | | [ "false" ]         | +---------------------*/

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.