bigfunctions > max_value
max_value¶
Call or Deploy max_value
?
✅ You can call this max_value
bigfunction directly from your Google Cloud Project (no install required).
- This
max_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
max_value(arr)
Description
Return max value of array (inspired from sql-snippets repo)
Examples¶
select bigfunctions.eu.max_value([1, 4, 3])
select bigfunctions.us.max_value([1, 4, 3])
select bigfunctions.europe_west1.max_value([1, 4, 3])
+-------+
| value |
+-------+
| 4 |
+-------+
Need help using max_value
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using max_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 products, and each product has a list of prices at different stores. You want to find the highest price for each product.
WITH Products AS (
SELECT
'Product A' AS product_name,
[10.99, 12.50, 11.75] AS prices
UNION ALL SELECT
'Product B' AS product_name,
[5.00, 5.50, 4.99] AS prices
UNION ALL SELECT
'Product C' AS product_name,
[20.00, 19.50, 21.25] AS prices
)
SELECT
product_name,
bigfunctions.us.max_value(prices) AS max_price
FROM Products;
This query uses the max_value
function to find the highest price within the prices
array for each product. The result will be:
+-------------+-----------+
| product_name | max_price |
+-------------+-----------+
| Product A | 12.5 |
| Product B | 5.5 |
| Product C | 21.25 |
+-------------+-----------+
This shows how max_value
can be practically used to extract the maximum value from an array of numbers within a larger dataset. This could be useful for things like pricing analysis, finding peak values in time series data (if stored as arrays), or determining the maximum score in a game played multiple times.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!