airflow.providers.snowflake.hooks.snowflake¶
Attributes¶
Classes¶
A client to interact with Snowflake. |
Module Contents¶
- class airflow.providers.snowflake.hooks.snowflake.SnowflakeHook(*args, **kwargs)[source]¶
Bases:
airflow.providers.common.sql.hooks.sql.DbApiHook
A client to interact with Snowflake.
This hook requires the snowflake_conn_id connection. The snowflake account, login, and, password field must be setup in the connection. Other inputs can be defined in the connection or hook instantiation.
- Parameters:
snowflake_conn_id – 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
insecure_mode – Turns off OCSP certificate checks. For details, see: How To: Turn Off OCSP Checking in Snowflake Client Drivers - Snowflake Community
Note
get_sqlalchemy_engine()
depends onsnowflake-sqlalchemy
- classmethod get_connection_form_widgets()[source]¶
Return connection widgets to add to connection form.
- get_oauth_token(conn_config=None, token_endpoint=None, grant_type='refresh_token')[source]¶
Generate temporary OAuth access token using refresh token in connection details.
- get_sqlalchemy_engine(engine_kwargs=None)[source]¶
Get an sqlalchemy_engine object.
- Parameters:
engine_kwargs – Kwargs used in
create_engine()
.- Returns:
the created engine.
- get_autocommit(conn)[source]¶
Get autocommit setting for the provided connection.
- Parameters:
conn – Connection to get autocommit setting from.
- Returns:
connection autocommit setting. True if
autocommit
is set to True on the connection. False if it is either not set, set to False, or the connection does not support auto-commit.
- run(sql: str | collections.abc.Iterable[str], autocommit: bool = ..., parameters: collections.abc.Iterable | collections.abc.Mapping[str, Any] | None = ..., handler: None = ..., split_statements: bool = ..., return_last: bool = ..., return_dictionaries: bool = ...) None [source]¶
- run(sql: str | collections.abc.Iterable[str], autocommit: bool = ..., parameters: collections.abc.Iterable | collections.abc.Mapping[str, Any] | None = ..., handler: collections.abc.Callable[[Any], T] = ..., split_statements: bool = ..., return_last: bool = ..., return_dictionaries: bool = ...) tuple | list[tuple] | list[list[tuple] | tuple] | None
Run a command or list of commands.
Pass a list of SQL statements to the SQL parameter to get them to execute sequentially. The result of the queries is returned if the
handler
callable is set.- Parameters:
sql – The SQL string to be executed with possibly multiple statements, or a list of sql statements to execute
autocommit – What to set the connection’s autocommit setting to before executing the query.
parameters – The parameters to render the SQL query with.
handler – The result handler which is called with the result of each statement.
split_statements – Whether to split a single SQL string into statements and run separately
return_last – Whether to return result for only last statement or for all after split.
return_dictionaries – Whether to return dictionaries rather than regular DBAPI sequences as rows in the result. The dictionaries are of form
{ 'column1_name': value1, 'column2_name': value2 ... }
.
- Returns:
Result of the last SQL statement if handler is set. None otherwise.
- get_openlineage_database_info(connection)[source]¶
Return database specific information needed to generate and parse lineage metadata.
This includes information helpful for constructing information schema query and creating correct namespace.
- Parameters:
connection – Airflow connection to reduce calls of get_connection method
- get_openlineage_database_dialect(_)[source]¶
Return database dialect used for SQL parsing.
For a list of supported dialects check: https://openlineage.io/docs/development/sql#sql-dialects
- get_openlineage_database_specific_lineage(task_instance)[source]¶
Emit separate OpenLineage events for each Snowflake query, based on executed query IDs.
If a single query ID is present, also add an ExternalQueryRunFacet to the returned lineage metadata.
Note that get_openlineage_database_specific_lineage is usually called after task’s execution, so if multiple query IDs are present, both START and COMPLETE event for each query will be emitted after task’s execution. If we are able to query Snowflake for query execution metadata, query event times will correspond to actual query’s start and finish times.
- Args:
task_instance: The Airflow TaskInstance object for which lineage is being collected.
- Returns:
An OperatorLineage object if a single query ID is found; otherwise None.