SQLExecuteQueryOperator for ClickHouse¶
Use the SQLExecuteQueryOperator to execute
SQL commands in a ClickHouse database.
Because ClickHouseHook extends
DbApiHook, no dedicated ClickHouse operator is
needed — the generic SQLExecuteQueryOperator handles DDL, DML, and analytical queries.
Using the Operator¶
Set the conn_id argument to the ID of a
ClickHouse connection.
Parameter |
Input |
|---|---|
Host: string |
ClickHouse server hostname |
Port: integer |
HTTP port (default: |
Login: string |
ClickHouse username (default: |
Password: string |
ClickHouse user password |
Database (Schema): string |
Default database (default: |
Extra: JSON dict |
|
An example usage of the SQLExecuteQueryOperator to connect to ClickHouse:
create_table = SQLExecuteQueryOperator(
task_id="create_table",
sql=CREATE_TABLE_SQL,
)
insert_rows = SQLExecuteQueryOperator(
task_id="insert_rows",
sql=INSERT_ROWS_SQL,
)
read_rows = SQLExecuteQueryOperator(
task_id="read_rows",
sql=f"SELECT id, name FROM {CLICKHOUSE_TABLE} ORDER BY id",
)
drop_table = SQLExecuteQueryOperator(
task_id="drop_table",
sql=DROP_TABLE_SQL,
)
Querying Data¶
Use a handler to return query results:
read_rows = SQLExecuteQueryOperator(
task_id="read_rows",
sql=f"SELECT id, name FROM {CLICKHOUSE_TABLE} ORDER BY id",
)
Note
session_settings passed to ClickHouseHook
directly (via hook_params) take precedence over any session_settings defined in the
connection’s extra JSON field. Conflicting keys are resolved in favor of the constructor argument.