Repository navigation
chore(logging): log debug sql lines from typed SQLQuery and SQLQueryStatus events - #807
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new event contract and SQL abridgement lack regression coverage, and the changelog still contains unresolved PR-link placeholders.
2 open issues
What changed in this PR
Aligns ClickHouse SQL debug logging with dbt’s standard typed events, improving structured logs and dbtRunner callback support.
Changes:
- Shares statement execution through
_run_statement, emittingSQLQueryandSQLQueryStatusevents with query IDs. - Uses high-resolution elapsed timing and honors SQL log abridgement without truncating executed statements.
- Adds a user-facing changelog entry.
| File | Description |
|---|---|
dbt/adapters/clickhouse/connections.py |
Unifies execution logging with typed events, query IDs, timing, and optional abridgement. |
CHANGELOG.md |
Documents the structured SQL logging improvement. |
Review effort: Balanced
canbekley
requested review from
koletzilla
and
a balanced review from Copilot
November 17, 2026 10:43
koletzilla
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
The default implementation of
SQLConnectionManagerand other adapters fire sql debug log events as typedSQLQueryandSQLQueryStatus, while dbt-clickhouse fires genericAdapterEventDebugevents. This has led to limitations in how debug log events could be processed (no structured fields, and no query id).This PR aligns query debug logging with dbt's standard way:
dbt_clickhouse adapter:prefix and the trailing...dbtRunnerreceive typed events (making adapter base tests such as UDFsBasic easier to run without clickhouse work-arounds)Example Output
Text log (logs/dbt.log), view model
Before:
After:
JSON log (--log-format-file json), view model
Before:
{"code": "E001", "name": "AdapterEventDebug", "level": "debug", "data": {"name": "dbt_clickhouse", "args": [], "base_msg": "On model.logdemo.my_model: /* {\"app\": ..."}} {"code": "E001", "name": "AdapterEventDebug", "level": "debug", "data": {"name": "dbt_clickhouse", "args": [], "base_msg": "SQL status: OK in 0.00 seconds"}}After:
{"code": "E016", "name": "SQLQuery", "level": "debug", "data": {"conn_name": "model.logdemo.my_model", "sql": "/* {\"app\": \"dbt\", ..."}} {"code": "E017", "name": "SQLQueryStatus", "level": "debug", "data": {"status": "OK", "elapsed": 0.002111166, "query_id": "a6d1a0ee-759f-47a7-abab-ea484776b540"}}Checklist
Note
Low Risk
Observability-only change to debug logging; query execution behavior is unchanged aside from consolidating execute/add_query through _run_statement.
Overview
The ClickHouse adapter now emits dbt’s standard
SQLQueryandSQLQueryStatusdebug events instead of custom adapter debug log lines, so JSON logs,dbtRunnercallbacks, and shared adapter tests see structured SQL metadata including the ClickHouse query ID and node context.executeandadd_queryshare a new_run_statementpath: both assign a UUIDquery_idfor the client call, usefire_eventfor start/status, and measure elapsed time withperf_counter. Optionalabridge_sql_logonadd_querylogs only the first 512 characters while still running the full SQL.Unit tests in
test_connections.pyassert the typed events, query ID wiring, and abridged logging behavior.Reviewed by Cursor Bugbot for commit 9b17086. Bugbot is set up for automated code reviews on this repo. Configure here.