airflow.providers.snowflake.hooks.snowflake_sql_api

Module Contents

Classes

SnowflakeSqlApiHook

A client to interact with Snowflake using SQL API and submit multiple SQL statements in a single request.

class airflow.providers.snowflake.hooks.snowflake_sql_api.SnowflakeSqlApiHook(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 submit 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, and an authentication mechanism from one of below: 1. JWT Token generated from private_key_file or private_key_content. Other inputs can be defined in the connection or hook instantiation. 2. OAuth Token generated from the refresh_token, client_id and client_secret specified in the connection

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

  • deferrable – Run operator in the deferrable mode.

property account_identifier: str[source]

Returns snowflake account identifier.

LIFETIME[source]
RENEWAL_DELTA[source]
get_private_key()[source]

Get the private key from snowflake connection.

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

Run the query in Snowflake using SnowflakeSQL API 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 (dict[str, Any] | None) – (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]

Form auth headers based on either OAuth token or JWT token from private key.

get_oauth_token()[source]

Generate temporary OAuth access token using refresh token in connection details.

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]

Make HTTP request to snowflake SQL API based on the provided query ids and log the response.

Parameters

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

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.

async get_sql_api_query_status_async(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.

Was this entry helpful?