astronomer.providers.snowflake.hooks.snowflake_sql_api¶
Classes¶
This class is deprecated and will be removed in 2.0.0. |
Module Contents¶
- 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
This class is deprecated and will be removed in 2.0.0. Use :class: ~airflow.providers.snowflake.hooks.snowflake_sql_api.SnowflakeSqlApiHook instead.
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¶
- snowflake_conn_id¶
- token_life_time¶
- token_renewal_delta¶
- private_key: Any = None¶
- 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 (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]¶
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.
- static process_query_status_response(resp, status_code)[source]¶
Process query_status response and generate event based on status Code
200: success 202: running 422 and else: error
- Parameters:
resp (dict[str, Any]) – json response from snowflake statements API
status_code (int) – status code of the response