Using AdbcHook¶
Use AdbcHook to interact with any database
that has an ADBC driver. The hook extends
DbApiHook, so it works transparently with
SQLExecuteQueryOperator and the other
operators from the common.sql provider — just pass conn_id pointing at an adbc
connection.
For direct hook usage (e.g. inside a @dag.task function), the example below demonstrates
creating a table, bulk-inserting rows via Arrow-native transfer, querying the results, and
cleaning up — all against a SQLite ADBC connection.
@dag.task
def create_table():
from airflow.providers.apache.arrow.hooks.adbc import AdbcHook
hook = AdbcHook(adbc_conn_id=CONN_ID)
hook.run("CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, name TEXT NOT NULL)")
@dag.task
def insert_rows():
from airflow.providers.apache.arrow.hooks.adbc import AdbcHook
hook = AdbcHook(adbc_conn_id=CONN_ID)
rows = [(1, "Alice"), (2, "Bob"), (3, "Carol")]
hook.insert_rows(table="users", rows=rows, target_fields=["id", "name"])
@dag.task
def query_rows():
from airflow.providers.apache.arrow.hooks.adbc import AdbcHook
hook = AdbcHook(adbc_conn_id=CONN_ID)
records = hook.get_records("SELECT id, name FROM users ORDER BY id")
assert len(records) == 3, f"Expected 3 rows, got {len(records)}"
@dag.task
def drop_table():
from airflow.providers.apache.arrow.hooks.adbc import AdbcHook
hook = AdbcHook(adbc_conn_id=CONN_ID)
hook.run("DROP TABLE IF EXISTS users")
create_table() >> insert_rows() >> query_rows() >> drop_table()
See Connection types for how to configure the adbc connection.