Using System Settings in Python SDK

System settings can change how a query is run in Firebolt. If you're using the Python SDK to submit queries, you can enable the settings for a connection and the settings will apply to every query run in the connection. You can also reset the settings to their default value in the connection.

Example

from firebolt.db import connectfrom firebolt.client import DEFAULT_API_URLusername = "your_username"password = "your_password"engine_name = "your_engine"database_name = "your_database"connection = connect(        engine_name=engine_name,        database=database_name,        username=username,        password=password,)cursor = connection.cursor()# This will set the count_distinct setting to 1 for every query executed in the connectioncursor.execute("SET firebolt_optimization_enable_exact_count_distinct = 1;")cursor.execute("SELECT COUNT(DISTINCT column) FROM table1;")print(cursor.fetchone())cursor.execute("SELECT COUNT(DISTINCT column) FROM table2;")print(cursor.fetchone())#this will reset all settings back to default for the connectioncursor.flush_parameters()cursor.execute("SELECT COUNT(DISTINCT column) FROM table1;")print(cursor.fetchone())cursor.execute("SELECT COUNT(DISTINCT column) FROM table2;")print(cursor.fetchone())cursor.close()

Caveat

It may be desirable to run queries asynchronously on the server. In the UI, this can be done with a SET command. With the SDK, it is accomplished by setting async_execution=True on the execute() command. This means it is only in effect for the query submitted, not for the duration of the connection:

from firebolt.db import connectfrom firebolt.client import DEFAULT_API_URLusername = "your_username"password = "your_password"engine_name = "your_engine"database_name = "your_database"connection = connect(        engine_name=engine_name,        database=database_name,        username=username,        password=password,)cursor = connection.cursor()# This query will execute asynchronously, and will need to have its status checked as  described in the documentationquery_id = cursor.execute("INSERT INTO table_a SELECT * FROM table_b;",async_execution=True)cursor.execute("SELECT COUNT(DISTINCT column) FROM table1;")print(cursor.fetchone())cursor.close()