max_value¶
max_value(arr)
Description¶
Return max value of array (inspired from sql-snippets repo)
Examples¶
Call or Deploy max_value
?
Call max_value
directly
The easiest way to use bigfunctions
max_value
function is deployed in 39 public datasets for all of the 39 BigQuery regions.- It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)
Public BigFunctions Datasets
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Deploy max_value
in your project
Why deploy?
- You may prefer to deploy
max_value
in your own project 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).
- Get started by reading the framework page
Deployment
max_value
function can be deployed with:
pip install bigfunctions
bigfun get max_value
bigfun deploy max_value
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 or Found a bug using max_value
?
Get help using max_value
The community can help! Engage the conversation on Slack
We also provide professional suppport.
Report a bug about 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.
We also provide professional suppport.
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!