bigfunctions > sleep
sleep¶
Call or Deploy sleep
?
✅ You can call this sleep
bigfunction directly from your Google Cloud Project (no install required).
- This
sleep
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
sleep(seconds)
Description
Sleep during seconds
seconds
Examples¶
Wait for 10 seconds
select bigfunctions.eu.sleep(10)
select bigfunctions.us.sleep(10)
select bigfunctions.europe_west1.sleep(10)
+----------+
| response |
+----------+
| ok |
+----------+
Need help using sleep
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using sleep
?
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¶
The sleep
function in BigQuery can be useful in a few scenarios, primarily related to testing and managing dependencies within scripts or workflows:
-
Testing BigQuery function performance: You can use
sleep
to introduce controlled delays and measure the execution time of other BigQuery functions or queries. This allows you to benchmark performance and identify bottlenecks. -
Simulating latency: In testing scenarios, you might want to simulate real-world conditions where there are delays in data processing or availability.
sleep
can help mimic these latencies. -
Managing dependencies in scripts: If you have a BigQuery script where one part needs to complete before another begins, you can use
sleep
to ensure a certain time has passed before the dependent part executes. However, this is generally not the ideal way to handle dependencies within a BigQuery script. BigQuery scripting features likeWAIT
clauses forMERGE
statements or explicitly checking for job completion status offer more robust solutions.sleep
would be a less reliable approach as execution times can vary. -
Rate limiting: If you're interacting with an external API or service via BigQuery and need to adhere to rate limits,
sleep
can be used to pause execution for a specified duration between calls. However, dedicated rate limiting libraries or built-in functionality within the API or service itself would be preferable for more precise control. -
Troubleshooting and debugging: In some cases, introducing a delay with
sleep
can be helpful for debugging timing-related issues or examining intermediate states within a complex BigQuery script.
Example (Testing performance):
-- Measure the time taken to execute a complex query
SELECT bigfunctions.eu.sleep(5); -- Introduce a delay to clear the cache (less reliable, better alternatives exist)
DECLARE start_time TIMESTAMP;
SET start_time = CURRENT_TIMESTAMP();
-- Your complex query here
SELECT * FROM large_table WHERE some_condition;
DECLARE end_time TIMESTAMP;
SET end_time = CURRENT_TIMESTAMP();
SELECT TIMESTAMP_DIFF(end_time, start_time, SECOND) AS execution_time;
Caveats: While sleep
can be useful in limited cases, relying heavily on it within production BigQuery scripts is generally discouraged. For dependency management, error handling, and performance optimization, using BigQuery's built-in features and best practices is more appropriate. Using sleep
for rate limiting is also suboptimal; dedicated rate-limiting mechanisms are more robust. It's primarily useful for simple testing and debugging scenarios.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!