bigfunctions > find_value
find_value¶
Call or Deploy find_value
?
✅ You can call this find_value
bigfunction directly from your Google Cloud Project (no install required).
- This
find_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
find_value(arr, value)
Description
Return the first offset
(zero-based index) of value
in array arr
(or null
if value
is not in arr
).
Examples¶
1. When value
is in array
select bigfunctions.eu.find_value([3, 4], 4)
select bigfunctions.us.find_value([3, 4], 4)
select bigfunctions.europe_west1.find_value([3, 4], 4)
+--------+
| offset |
+--------+
| 1 |
+--------+
2. When value
is not in array
select bigfunctions.eu.find_value([3, 4], 7)
select bigfunctions.us.find_value([3, 4], 7)
select bigfunctions.europe_west1.find_value([3, 4], 7)
+--------+
| offset |
+--------+
| null |
+--------+
Need help using find_value
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using find_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¶
You have a table of customer orders, and each order has an array of product IDs. You want to find the position of a specific product ID within each order's product array.
Table Schema:
CREATE OR REPLACE TABLE `your_project.your_dataset.orders` (
order_id INT64,
product_ids ARRAY<INT64>
);
INSERT INTO `your_project.your_dataset.orders` (order_id, product_ids) VALUES
(1, [101, 102, 103, 104]),
(2, [102, 105, 106]),
(3, [101, 103, 107, 102]);
Use Case: Finding the position of product ID 102:
SELECT
order_id,
bigfunctions.your_region.find_value(product_ids, 102) AS product_102_position
FROM
`your_project.your_dataset.orders`;
Result:
+---------+----------------------+
| order_id | product_102_position |
+---------+----------------------+
| 1 | 1 |
| 2 | 0 |
| 3 | 3 |
+---------+----------------------+
Explanation:
- The
find_value
function searches theproduct_ids
array for the value102
. - It returns the zero-based index (position) of the first occurrence of
102
. - For
order_id = 1
,102
is at index 1. - For
order_id = 2
,102
is at index 0. - For
order_id = 3
,102
is at index 3.
Other Potential Use Cases:
- Inventory Management: Find the location of a specific item within a warehouse represented as an array.
- Log Analysis: Find the first occurrence of a specific error code within a log entry containing an array of codes.
- User Behavior Analysis: Determine the position of a specific action within a user's sequence of actions on a website.
Remember to replace your_project
, your_dataset
, and your_region
with your actual values. For example, if your dataset is in the us-central1
region, you would use bigfunctions.us_central1
.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!