airflow.providers.apache.arrow.hooks.adbc¶
Classes¶
General-purpose Airflow hook for interacting with databases via the Arrow Database Connectivity (ADBC) standard. |
Functions¶
|
Return results for DbApiHook.run(). |
|
Module Contents¶
- airflow.providers.apache.arrow.hooks.adbc.fetch_all_handler(cursor)[source]¶
Return results for DbApiHook.run().
- class airflow.providers.apache.arrow.hooks.adbc.AdbcHook(*args, schema=None, log_sql=True, **kwargs)[source]¶
Bases:
airflow.providers.common.sql.hooks.sql.DbApiHookGeneral-purpose Airflow hook for interacting with databases via the Arrow Database Connectivity (ADBC) standard.
This hook enables connections to any database supported by an ADBC driver, using the Python ADBC driver manager. It provides methods for executing SQL queries, inserting rows in bulk, and handling Arrow-native data transfers.
- Key Features:
Supports chunked and batched inserts using Apache Arrow RecordBatches for efficient data transfer.
Discovers and loads ADBC drivers dynamically based on connection extras or naming conventions.
Handles dialect-specific connection URIs and driver entrypoints.
Integrates with Airflow’s connection system (conn_id, extras, etc.).
Provides custom placeholder replacement for parameterized SQL queries.
Loads rows with the driver’s bulk ingest (
adbc_ingest, e.g.COPYon PostgreSQL) by default, or binds them with DBAPIexecutemany(fast_executemany=False).Exposes configuration via connection extras: driver, entrypoint, db_kwargs, conn_kwargs, dialect.
- Connection Extras:
driver: Name of the ADBC driver to use (e.g., “adbc_driver_postgresql”).
entrypoint: Optional Python entrypoint for the driver.
db_kwargs: Driver-specific database initialization options passed to
AdbcDatabase. Keys and value types are defined by the driver (e.g.,"username","password"for the PostgreSQL driver). Do not put ADBC connection options here — they belong inconn_kwargs.conn_kwargs: ADBC connection options as string key-value pairs. Keys must use the canonical dotted ADBC option names, for example:
"adbc.connection.autocommit": "true","adbc.connection.read_only": "true","adbc.connection.current_catalog": "my_catalog","adbc.connection.current_db_schema": "my_schema". Short names such asautocommitorread_onlyare not recognized by ADBC drivers and will raiseNotSupportedError.dialect: SQL dialect name (default: “default”).
- Example usage:
hook = AdbcHook(adbc_conn_id=”my_adbc_conn”) records = hook.get_records(“SELECT * FROM my_table”)
- For more details, see:
Apache Arrow ADBC Python API: https://arrow.apache.org/adbc/current/python/api/adbc_driver_manager.html
Airflow SQL hooks: https://airflow.apache.org/docs/apache-airflow/stable/howto/custom-operator.html#hooks
- property uri: str[source]¶
Return the URI handed to the driver.
A host that already is a URI or a path (
postgresql://user:pass@host:5432/db,file::memory:,:memory:,/data/app.db) is passed through unchanged. Otherwise the URI is built as<dialect>://login:password@host:port/schemafrom the connection’s fields. Airflow’s own connection URI is of no use here: its query string carries the extras, which drivers such as libpq refuse as unknown parameters.
- set_autocommit(conn, autocommit)[source]¶
Set autocommit on the ADBC connection.
The DBAPI attribute
conn.autocommithas no effect on the underlying ADBC driver; the real lever is theadbc.connection.autocommitoption. This override applies the option at the driver level, then calls super() to keep the Python-level bookkeeping attribute in sync so that the base classget_autocommit()andrun()commit-guard behave correctly.
- get_records(sql, parameters=None)[source]¶
Execute the sql and return a set of records.
- Parameters:
sql (str | list[str]) – the sql statement to be executed (str) or a list of sql statements to execute
parameters (collections.abc.Iterable | collections.abc.Mapping[str, Any] | None) – The parameters to render the SQL query with.
- insert_rows(table, rows, target_fields=None, commit_every=1000, replace=False, *, executemany=False, fast_executemany=True, autocommit=False, **kwargs)[source]¶
Insert a collection of tuples into a table.
Rows are converted to Arrow
RecordBatchobjects and inserted in chunks; each chunk (of sizecommit_every) is done in a new transaction.- Parameters:
table – Name of the target table, optionally prefixed with its schema (
schema.table).rows – The rows to insert into the table
target_fields – The names of the columns to fill in the table
commit_every – The maximum number of rows to insert in one transaction. Set to 0 to insert all rows in one transaction.
replace – Whether to replace instead of insert. Replacing always binds the rows to the generated statement, because bulk ingest cannot express it.
executemany – Kept for signature compatibility with
insert_rows(); rows are always sent as one Arrow batch per chunk.fast_executemany – If True (default), load each batch with the driver’s bulk ingest (
cursor.adbc_ingest,COPYon PostgreSQL). If the driver does not implement bulk ingest, falls back to binding. If False, bind each batch to theINSERTstatement withcursor.executemany.autocommit – What to set the connection’s autocommit setting to before executing the query.