airflow.providers.snowflake.hooks.snowflake

Module Contents

Classes

SnowflakeHook

A client to interact with Snowflake.

Attributes

T

airflow.providers.snowflake.hooks.snowflake.T[source]
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 on snowflake-sqlalchemy

See also

For more information on how to use this Snowflake connection, take a look at the guide: SnowflakeOperator

conn_name_attr = 'snowflake_conn_id'[source]
default_conn_name = 'snowflake_default'[source]
conn_type = 'snowflake'[source]
hook_name = 'Snowflake'[source]
supports_autocommit = True[source]
classmethod get_connection_form_widgets()[source]

Return connection widgets to add to connection form.

classmethod get_ui_field_behaviour()[source]

Return custom field behaviour.

get_uri()[source]

Override DbApiHook get_uri method for get_sqlalchemy_engine().

get_conn()[source]

Return a snowflake.connection object.

get_sqlalchemy_engine(engine_kwargs=None)[source]

Get an sqlalchemy_engine object.

Parameters

engine_kwargs – Kwargs used in create_engine().

Returns

the created engine.

set_autocommit(conn, autocommit)[source]

Set the autocommit flag on the connection.

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 | Iterable[str], autocommit: bool = ..., parameters: Iterable | Mapping[str, Any] | None = ..., handler: None = ..., split_statements: bool = ..., return_last: bool = ..., return_dictionaries: bool = ...) None[source]
run(sql: str | Iterable[str], autocommit: bool = ..., parameters: Iterable | Mapping[str, Any] | None = ..., handler: 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_default_schema()[source]

Attempt to get current schema.

Usually SELECT CURRENT_SCHEMA(); should work. However, apparently you may set database without schema and get results from SELECT CURRENT_SCHEMAS(); but not from SELECT CURRENT_SCHEMA();. It still may return nothing if no database is set in connection.

get_openlineage_database_specific_lineage(_)[source]

Return additional database specific lineage, e.g. query execution information.

This method is called only on completion of the task.

Parameters

task_instance – this may be used to retrieve additional information that is collected during runtime of the task

Was this entry helpful?