astronomer.providers.snowflake.hooks.snowflake_sql_api

Module Contents

Classes

SnowflakeSqlApiHookAsync

A client to interact with Snowflake using SQL API and allows submitting

class astronomer.providers.snowflake.hooks.snowflake_sql_api.SnowflakeSqlApiHookAsync(snowflake_conn_id, token_life_time=LIFETIME, token_renewal_delta=RENEWAL_DELTA, *args, **kwargs)[source]

Bases: airflow.providers.snowflake.hooks.snowflake.SnowflakeHook

A client to interact with Snowflake using SQL API and allows submitting multiple SQL statements in a single request. In combination with aiohttp, make post request to submit SQL statements for execution, poll to check the status of the execution of a statement. Fetch query results asynchronously.

This hook requires the snowflake_conn_id connection. This hooks mainly uses account, schema, database, warehouse, private_key_file or private_key_content field must be setup in the connection. Other inputs can be defined in the connection or hook instantiation.

Parameters:
  • snowflake_conn_id (str) – Reference to Snowflake connection id

  • account – snowflake account name

  • authenticator – authenticator for Snowflake. ‘snowflake’ (default) to use the internal Snowflake authenticator ‘externalbrowser’ to authenticate using your web browser and Okta, ADFS or any other SAML 2.0-compliant identify provider (IdP) that has been defined for your account ‘https://<your_okta_account_name>.okta.com’ to authenticate through native Okta.

  • warehouse – name of snowflake warehouse

  • database – name of snowflake database

  • region – name of snowflake region

  • role – name of snowflake role

  • schema – name of snowflake schema

  • session_parameters – You can set session-level parameters at the time you connect to Snowflake

  • token_life_time (datetime.timedelta) – lifetime of the JWT Token in timedelta

  • token_renewal_delta (datetime.timedelta) – Renewal time of the JWT Token in timedelta

LIFETIME
RENEWAL_DELTA
get_private_key()[source]

Gets the private key from snowflake connection

execute_query(sql, statement_count, query_tag='', bindings=None)[source]

Using SnowflakeSQL API, run the query in snowflake by making API request

Parameters:
  • sql (str) – the sql string to be executed with possibly multiple statements

  • statement_count (int) – set the MULTI_STATEMENT_COUNT field to the number of SQL statements in the request

  • query_tag (str) – (Optional) Query tag that you want to associate with the SQL statement. For details, see https://docs.snowflake.com/en/sql-reference/parameters.html#label-query-tag parameter.

  • bindings (Optional[Dict[str, Any]]) – (Optional) Values of bind variables in the SQL statement. When executing the statement, Snowflake replaces placeholders (? and :name) in the statement with these specified values.

get_headers()[source]

Based on the private key, and with connection details JWT Token is generated and header is formed

get_request_url_header_params(query_id)[source]

Build the request header Url with account name identifier and query id from the connection params

Parameters:

query_id (str) – statement handles query ids for the individual statements.

check_query_output(query_ids)[source]

Based on the query ids passed as the parameter make HTTP request to snowflake SQL API and logs the response

Parameters:

query_ids (List[str]) – statement handles query id for the individual statements.

async get_sql_api_query_status(query_id)[source]

Based on the query id async HTTP request is made to snowflake SQL API and return response.

Parameters:

query_id (str) – statement handle id for the individual statements.