INSERT, STOP ENGINE, and ALTER ENGINE, where keeping an HTTP connection open is both unreliable and unnecessary, and where the statement might return zero rows. In addition, tracking them can be challenging. Using an asynchronous query allows you to check the status of operations at intervals, based on the expected duration.
You should use asynchronous queries for any supported operation that may take more than a few minutes for which there are no results.
Supported asynchronous queries
- INSERT – Inserts one or more values into a specified table.
- COPY FROM – Loads data from an Amazon S3 bucket into Firebolt.
- COPY TO – Copies the result of a
SELECTquery to an Amazon S3 location. - VACUUM – Optimizes tablets for query performance.
- CREATE AGGREGATING INDEX – Creates an index for precomputing and storing frequent aggregations.
- CREATE AS SELECT – Creates a table and loads data into it based on a
SELECTquery. - Engine commands including ALTER ENGINE, STOP ENGINE, and START ENGINE. By default, Firebolt engines finish running queries before returning results, which can take significant time. Starting an engine can also take more than a few minutes.
How to submit an asynchronous query
You can only submit a synchronous query programmatically using the Firebolt API or the following listed drivers. Every SQL statement submitted using the Firebolt Develop Space user interface is a synchronous query. The following are required prerequisites to submit a query programmatically:- A Firebolt account – Ensure that you have access to an active Firebolt account. If you don’t have access, you can sign up for an account. For more information about how to register with Firebolt, see Get started with Firebolt.
- A Firebolt service account – You must have access to an active Firebolt service account, which facilitates programmatic access to Firebolt.
- A user associated with the Firebolt service account – You must associate a user with your service account, and the user must have the necessary permissions to run the query on the specified database using the specified engine.
- Sufficient permissions If you want to query user data through a specific engine, you must have sufficient permissions on the engine, as well as on any tables and databases you access.
Use a Firebolt Driver
Use a Firebolt driver to connect to a Firebolt database, authenticate securely, and run SQL statements with minimal setup. The driver provides built-in methods for running SQL statements, handling responses, and managing connections. Only some Firebolt drivers support synchronous queries. See the documentation for each driver for specific details on how to submit asynchronous queries programmatically:- Python SDK – Firebolt Python SDK
- Node.js – Firebolt Node SDK
Submit a query
Submitting a query through a Firebolt drivers and SDKs have similar formats. The following code example shows how to submit an asynchronous query using the Python SDK. For other languages, consult the specific driver for details: The following code example establishes a connection to a Firebolt database using a service account, submits an asynchronousINSERT statement that groups generated numbers, periodically checks its run status, and then retrieves the row count from the example table:
Check query status
The query status token is included in the initial response when the query is submitted. If needed, you can also retrieve the token from the engine_running_queries view. To check the status of an asynchronous query, use the token with theCALL fb_GetAsyncStatus function as follows.