bigfunctions > get_value
get_value¶
Call or Deploy get_value
?
✅ You can call this get_value
bigfunction directly from your Google Cloud Project (no install required).
- This
get_value
function is deployed inbigfunctions
GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error). - Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework
Public BigFunctions Datasets:
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Description¶
Signature
get_value(key_value_items, search_key)
Description
Return the first value
with a key search_key
from key_value_items
(or return null
if search_key
does not exist in key_value_items
).
Examples¶
select bigfunctions.eu.get_value([struct('a' as key, 8 as value), struct('b' as key, 9 as value)], 'a')
select bigfunctions.us.get_value([struct('a' as key, 8 as value), struct('b' as key, 9 as value)], 'a')
select bigfunctions.europe_west1.get_value([struct('a' as key, 8 as value), struct('b' as key, 9 as value)], 'a')
+-------+
| value |
+-------+
| 8 |
+-------+
select bigfunctions.eu.get_value([struct('a' as key, 8 as value), struct('b' as key, 9 as value)], 'c')
select bigfunctions.us.get_value([struct('a' as key, 8 as value), struct('b' as key, 9 as value)], 'c')
select bigfunctions.europe_west1.get_value([struct('a' as key, 8 as value), struct('b' as key, 9 as value)], 'c')
+-------+
| value |
+-------+
| null |
+-------+
3. When there are multiple occurences of search_key
, return the first found value
select bigfunctions.eu.get_value([struct('a' as key, 8 as value), struct('a' as key, 9 as value)], 'a')
select bigfunctions.us.get_value([struct('a' as key, 8 as value), struct('a' as key, 9 as value)], 'a')
select bigfunctions.europe_west1.get_value([struct('a' as key, 8 as value), struct('a' as key, 9 as value)], 'a')
+-------+
| value |
+-------+
| 8 |
+-------+
Need help using get_value
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using get_value
?
If the function does not work as expected, please
- report a bug so that it can be improved.
- or open the discussion with the community on Slack.
For professional suppport, don't hesitate to chat with us.
Use cases¶
This get_value
function is useful for extracting values from arrays of key-value pairs (structs). Here are a few use cases:
1. Parameter Extraction: Imagine you have a table storing event data, where one column contains parameters as an array of key-value structs:
| event_id | parameters |
|----------|-------------------------------------------------|
| 1 | [{'key': 'user_id', 'value': '123'}, {'key': 'event_type', 'value': 'purchase'}] |
| 2 | [{'key': 'item_id', 'value': '456'}, {'key': 'user_id', 'value': '789'}] |
You could use get_value
to extract the user_id
for each event:
SELECT
event_id,
bigfunctions.YOUR_REGION.get_value(parameters, 'user_id') AS user_id
FROM
your_table;
This would give you:
| event_id | user_id |
|----------|---------|
| 1 | 123 |
| 2 | 789 |
2. Configuration Management: Suppose you store configuration settings as key-value pairs in a table:
| setting_group | settings |
|---------------|-------------------------------------------------|
| website | [{'key': 'theme', 'value': 'dark'}, {'key': 'font_size', 'value': '16px'}] |
| mobile_app | [{'key': 'version', 'value': '1.2.3'}, {'key': 'platform', 'value': 'ios'}] |
You could retrieve specific settings using get_value
:
SELECT
setting_group,
bigfunctions.YOUR_REGION.get_value(settings, 'theme') AS theme
FROM
your_config_table
WHERE setting_group = 'website';
3. Product Attributes: E-commerce platforms often store product attributes as key-value pairs. get_value
can help extract these attributes:
| product_id | attributes |
|------------|-------------------------------------------------|
| 1 | [{'key': 'color', 'value': 'red'}, {'key': 'size', 'value': 'L'}] |
| 2 | [{'key': 'weight', 'value': '1kg'}, {'key': 'material', 'value': 'cotton'}] |
You can extract the color of product 1 with:
SELECT bigfunctions.YOUR_REGION.get_value(attributes, 'color') AS color
FROM your_product_table
WHERE product_id = 1;
These are just a few examples. Anytime you have data stored as an array of key-value pairs in BigQuery, get_value
can be a convenient way to access the values associated with specific keys. Remember to replace YOUR_REGION
with the appropriate BigQuery region for your data.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!