airflow.providers.snowflake.hooks.snowflake

Module Contents

Classes

SnowflakeHook

A client to interact with Snowflake.

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 host, 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]
static get_connection_form_widgets()[source]

Returns connection widgets to add to connection form

static get_ui_field_behaviour()[source]

Returns custom field behaviour

get_uri()[source]

Override DbApiHook get_uri method for get_sqlalchemy_engine()

get_conn()[source]

Returns 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]

Sets the autocommit flag on the connection

get_autocommit(conn)[source]

Get autocommit setting for the provided connection. Return True if conn.autocommit is set to True. Return False if conn.autocommit is not set or set to False or conn does not support autocommit.

Parameters

conn – Connection to get autocommit setting from.

Returns

connection autocommit setting.

run(sql, autocommit=False, parameters=None, handler=None, split_statements=True, return_last=True)[source]

Runs a command or a list of commands. Pass a list of sql statements to the sql parameter to get them to execute sequentially. The variable execution_info is returned so that it can be used in the Operators to modify the behavior depending on the result of the query (i.e fail the operator if the copy has processed 0 files)

Parameters
  • sql (str | Iterable[str]) – the sql string to be executed with possibly multiple statements, or a list of sql statements to execute

  • autocommit (bool) – What to set the connection’s autocommit setting to before executing the query.

  • parameters (Iterable | Mapping | None) – The parameters to render the SQL query with.

  • handler (Callable | None) – The result handler which is called with the result of each statement.

  • split_statements (bool) – Whether to split a single SQL string into statements and run separately

  • return_last (bool) – Whether to return result for only last statement or for all after split

Returns

return only result of the LAST SQL expression if handler was provided.

Return type

Any | list[Any] | None

Was this entry helpful?