Map functions

GoogleSQL for Bigtable supports the following map functions.

Function list

Name Summary
MAP_CONTAINS_KEY Checks if a key is in a map.
MAP_KEYS Gets an array of lexicographically sorted keys from a map.
MAP_VALUES Gets an array of lexicographically key-sorted values from a map.

MAP_CONTAINS_KEY

MAP_CONTAINS_KEY(input_map, key_to_find)

Description

Checks if a key is in a map. Returns TRUE if the key is found. Otherwise, returns FALSE.

Definitions

  • input_map: A MAP<K,V> value that represents the map to search. If this value is NULL, the function returns NULL.
  • key_to_find: The key to find in the map.

Return type

BOOL

Examples

The following query checks if a column called cell_plan in a table called test_table has a key called data_plan_05gb:

SELECT MAP_CONTAINS_KEY(cell_plan, b'data_plan_05gb') AS results
FROM test_table

/*---------*
 | results |
 +---------+
 | TRUE    |
 | TRUE    |
 | FALSE   |
 | FALSE   |
 | FALSE   |
 *---------*/

MAP_KEYS

MAP_KEYS(input_map)

Description

Gets an array of lexicographically sorted keys from a map.

Definitions

  • input_map: A MAP<K,V> value that represents the map to query. If this value is NULL, the function returns NULL.

Return type

ARRAY<K>

Examples

The following query gets an lexicographically sorted list of keys from a table called test_table:

SELECT MAP_KEYS(cell_plan) AS results
FROM test_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 lexicographically key-sorted values from a map.

Definitions

  • input_map: A MAP<K,V> value that represents the map to query. If this value is NULL, the function returns NULL.

Return type

ARRAY<V>

Examples

The following query gets the key-sorted values from a table called test_table:

SELECT MAP_VALUES(cell_plan) AS results
FROM test_table

/*---------------------*
 | results             |
 +---------------------+
 | [ "true", "false" ] |
 | [ "false" ]         |
 | []                  |
 | [ "false" ]         |
 | [ "false" ]         |
 *---------------------*/