airflow.providers.oracle.hooks.oracle¶
Attributes¶
Classes¶
Interact with Oracle SQL. |
Module Contents¶
- class airflow.providers.oracle.hooks.oracle.OracleHook(*args, thick_mode=None, thick_mode_lib_dir=None, thick_mode_config_dir=None, fetch_decimals=None, fetch_lobs=None, **kwargs)[source]¶
Bases:
airflow.providers.common.sql.hooks.sql.DbApiHookInteract with Oracle SQL.
- Parameters:
oracle_conn_id – The Oracle connection id used for Oracle credentials.
thick_mode (bool | None) – Specify whether to use python-oracledb in thick mode. Defaults to False. If set to True, you must have the Oracle Client libraries installed. See oracledb docs<https://python-oracledb.readthedocs.io/en/latest/user_guide/initialization.html> for more info.
thick_mode_lib_dir (str | None) – Path to use to find the Oracle Client libraries when using thick mode. If not specified, defaults to the standard way of locating the Oracle Client library on the OS. See oracledb docs <https://python-oracledb.readthedocs.io/en/latest/user_guide/initialization.html#setting-the-oracle-client-library-directory> for more info.
thick_mode_config_dir (str | None) – Path to use to find the Oracle Client library configuration files when using thick mode. If not specified, defaults to the standard way of locating the Oracle Client library configuration files on the OS. See oracledb docs <https://python-oracledb.readthedocs.io/en/latest/user_guide/initialization.html#optional-oracle-net-configuration-files> for more info.
fetch_decimals (bool | None) – Specify whether numbers should be fetched as
decimal.Decimalvalues. See defaults.fetch_decimals <https://python-oracledb.readthedocs.io/en/latest/api_manual/defaults.html#defaults.fetch_decimals> for more info.fetch_lobs (bool | None) – Specify whether to fetch strings/bytes for CLOBs or BLOBs instead of locators. See defaults.fetch_lobs <https://python-oracledb.readthedocs.io/en/latest/api_manual/defaults.html#defaults.fetch_decimals> for more info.
- get_conn()[source]¶
Get an Oracle connection object.
Optional parameters for using a custom DSN connection (instead of using a server alias from tnsnames.ora) The dsn (data source name) is the TNS entry (from the Oracle names server or tnsnames.ora file), or is a string like the one returned from
makedsn().- Parameters:
dsn – the data source name for the Oracle server
service_name – the db_unique_name of the database that you are connecting to (CONNECT_DATA part of TNS)
sid – Oracle System ID that identifies a particular database on a system
wallet_location – Specify the directory where the wallet can be found.
wallet_password – the password to use to decrypt the wallet, if it is encrypted. For Oracle Autonomous Database this is the password created when downloading the wallet.
ssl_server_cert_dn – Specify the distinguished name (DN) which should be matched with the server. This value is ignored if the
ssl_server_dn_matchparameter is not set to the value True.ssl_server_dn_match – Specify whether the server certificate distinguished name (DN) should be matched in addition to the regular certificate verification that is performed.
cclass – the connection class to use for Database Resident Connection Pooling (DRCP).
pool_name – the name of the DRCP pool when using multi-pool DRCP with Oracle Database 23.4, or higher.
You can set these parameters in the extra fields of your connection as in
{"dsn": ("(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host)(PORT=1521))(CONNECT_DATA=(SID=sid)))")}
see more param detail in oracledb.connect
- insert_rows(table, rows, target_fields=None, commit_every=1000, replace=False, **kwargs)[source]¶
Insert a collection of tuples into a table.
All data to insert are treated as one transaction. Changes from standard DbApiHook implementation:
Oracle SQL queries can not be terminated with a semicolon (
;).Replace NaN values with NULL using
numpy.nan_to_num(not usingis_nan()because of input types error for strings).Coerce datetime cells to Oracle DATETIME format during insert.
- Parameters:
table (str) – target Oracle table, use dot notation to target a specific database
target_fields – the names of the columns to fill in the table
commit_every (int) – the maximum number of rows to insert in one transaction Default 1000, Set greater than 0. Set 1 to insert each row in each single transaction
replace (bool | None) – Whether to replace instead of insert. Currently not implemented.
- bulk_insert_rows(table, rows, target_fields=None, commit_every=5000, sequence_column=None, sequence_name=None)[source]¶
Perform bulk inserts efficiently for Oracle DB.
This uses prepared statements via executemany(). For best performance, pass in rows as an iterator.
- Parameters:
table (str) – target Oracle table, use dot notation to target a specific database
target_fields (list[str] | None) – the names of the columns to fill in the table, default None. If None, each rows should have some order as table columns name
commit_every (int) – the maximum number of rows to insert in one transaction Default 5000. Set greater than 0. Set 1 to insert each row in each transaction
sequence_column (str | None) – the column name to which the sequence will be applied, default None.
sequence_name (str | None) – the names of the sequence_name in the table, default None.
- callproc(identifier, autocommit=False, parameters=None)[source]¶
Call the stored procedure identified by the provided string.
Any OUT parameters must be provided with a value of either the expected Python type (e.g., int) or an instance of that type.
The return value is a list or mapping that includes parameters in both directions; the actual return type depends on the type of the provided parameters argument.
See https://python-oracledb.readthedocs.io/en/latest/api_manual/cursor.html#Cursor.var for further reference.