airflow.providers.duckdb.operators.duckdb¶
Classes¶
Run SQL against an in-process DuckDB database. |
Module Contents¶
- class airflow.providers.duckdb.operators.duckdb.DuckDBExecuteQueryOperator(*, conn_id=DuckDBHook.default_conn_name, **kwargs)[source]¶
Bases:
airflow.providers.common.sql.operators.sql.SQLExecuteQueryOperatorRun SQL against an in-process DuckDB database.
Unlike the other
SQLExecuteQueryOperatorsubclasses this operator does not require an Airflow connection to exist: with noduckdb_defaultconnection configured it runs against an in-memory database, which is the common case for a task that reads its input, transforms it and writes its output back out.When a connection does exist, its type selects the hook. A provider can therefore ship a DuckDB connection type that adds its own behaviour (the Amazon provider’s
duckdb_awsbrokers AWS credentials, for example) and a Dag moves between them by changing connections.See also
For more information on how to use this operator, take a look at the guide: Run a query
- Parameters:
sql – the SQL statement, list of statements, or
.sqltemplate file to run.conn_id (str) – DuckDB connection to use, or a connection of another DuckDB type such as
duckdb_aws. The default connection need not exist, in which case an in-memory database is used. Any other id must exist, and raises if it does not.database – DuckDB database to open, for example
/tmp/analytics.duckdb. Overrides both the connection andhook_params["database"].hook_params – extra keyword arguments for
DuckDBHook, for example{"extensions": ["httpfs"], "memory_limit": "2GB"}.
- hook_class: ClassVar[type[airflow.providers.duckdb.hooks.duckdb.DuckDBHook]][source]¶
- get_db_hook()[source]¶
Resolve the hook from the connection, and build one directly when there is no connection.
BaseSQLOperatorresolves the hook throughBaseHook.get_connection(conn_id).get_hook(), which raises when the connection is absent. DuckDB needs no connection to be useful, so a missing one is handed tohook_classto interpret rather than being an error here.When the connection does exist its type chooses the hook. That is what lets another provider add cloud-specific behaviour, such as brokering credentials, without a Dag having to swap operator: pointing this operator at a connection of that type is enough.