airflow.providers.jdbc.hooks.jdbc
¶
Module Contents¶
Functions¶
|
Context manager that suppresses the given exceptions and logs a warning message. |
- airflow.providers.jdbc.hooks.jdbc.suppress_and_warn(*exceptions)[source]¶
Context manager that suppresses the given exceptions and logs a warning message.
- class airflow.providers.jdbc.hooks.jdbc.JdbcHook(*args, driver_path=None, driver_class=None, **kwargs)[source]¶
Bases:
airflow.providers.common.sql.hooks.sql.DbApiHook
General hook for JDBC access.
JDBC URL, username and password will be taken from the predefined connection. Note that the whole JDBC URL must be specified in the “host” field in the DB. Raises an airflow error if the given connection id doesn’t exist.
- To configure driver parameters, you can use the following methods:
Supply them as constructor arguments when instantiating the hook.
Set the “driver_path” and/or “driver_class” parameters in the “hook_params” dictionary when creating the hook using SQL operators.
Set the “driver_path” and/or “driver_class” extra in the connection and correspondingly enable the “allow_driver_path_in_extra” and/or “allow_driver_class_in_extra” options in the “providers.jdbc” section of the Airflow configuration. If you’re enabling these options in Airflow configuration, you should make sure that you trust the users who can edit connections in the UI to not use it maliciously.
Define the “sqlalchemy_scheme” property in the extra of the connection if you want to use the SQLAlchemy engine from the JdbcHook. When using the JdbcHook, the “sqlalchemy_scheme” will by default have the “jdbc” value, which is a protocol, not a database scheme or dialect. So in order to be able to use SQLAlchemy with the JdbcHook, you need to define the “sqlalchemy_scheme” property in the extra of the connection.
Patch the
JdbcHook.default_driver_path
and/orJdbcHook.default_driver_class
values in thelocal_settings.py
file.
See JDBC connection for full documentation.
- Parameters
- property sqlalchemy_url: sqlalchemy.engine.URL[source]¶
Return a Sqlalchemy.engine.URL object from the connection.
Needs to be implemented in the provider subclass to return the sqlalchemy.engine.URL object.
- Returns
the extracted sqlalchemy.engine.URL object.
- Return type
- 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 autocommit for the given connection.
- Parameters
conn (jaydebeapi.Connection) – The connection.
autocommit (bool) – The connection’s autocommit setting.
- get_autocommit(conn)[source]¶
Get autocommit setting for the provided connection.
- Parameters
conn (jaydebeapi.Connection) – 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.- Return type