Skip to content

Add a harness that runs the ClickHouse core SQL tests through clickhouse-connect - #1223

Merged
joe-clickhouse merged 7 commits into
mainfrom
polyglot/core-sql-tests
Nov 21, 2026
Merged

joe-clickhouse merged 7 commits into
mainfrom
polyglot/core-sql-tests

Conversation

@polyglotAI-bot

@polyglotAI-bot polyglotAI-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR adds tests/clickhouse-test-runner/, a harness that runs a curated subset of the ClickHouse core SQL tests (tests/queries/0_stateless) through clickhouse-connect, nightly in CI. The goal is to find client bugs: the upstream .reference files are the oracle for how clickhouse-connect reads each value.

Tracking issue: ClickHouse/integrations#809

How it works:

  • bin/clickhouse is a small program that imitates clickhouse-client well enough for tests/clickhouse-test to drive it unchanged: the same flags, stdin and --query, test hints (serverError, clientError, echo), statement splitting as ClientBase::executeMultiQuery, inline INSERT data, and extract-from-config.
  • It uses the client as a user does: one get_client(...) with one session_id for the whole invocation (so SET, USE and temporary tables last), query() for statements with a result, command() for the rest, command-line settings through settings=. The default C-accelerated decoding. No pandas, numpy or Arrow paths.
  • A type-directed renderer writes result_rows as TabSeparated text from column_types. It never passes FORMAT to the server. Live tests compare its output with the server's own FORMAT TSV output for many expressions.
  • HTTP only, because clickhouse-connect speaks only HTTP. --port maps to CLICKHOUSE_PORT_HTTP.
  • The design follows the Go harness (test: run ClickHouse core SQL tests through clickhouse-go clickhouse-go#2141): the same scripts, allowlist format, group IDs where the cause is the same, and triage rules.

Files:

  • clickhouse_test_runner/: the program (args, split, hint, lexer, render, runner, formats), and errorcodes.py, which scripts/fetch-upstream.sh generates from src/Common/ErrorCodes.cpp of the same upstream checkout.
  • test_args.py, test_split.py, test_render.py (212 unit tests, many cases ported from the Go harness), test_live.py (79 live test cases, CLICKHOUSE_TEST_RUNNER_LIVE=1).
  • allowlist.txt, clickhouse-version (26.10.4.207: the server image and the upstream tag v26.10.4.207-stable).
  • scripts/: fetch-upstream.sh, run-upstream-tests.sh (shards, KNOWN_FAILURES=<id>, version check, warning for missing tests), run-with-real-client.sh, pinned-version.sh, selectors.sh, gen-error-codes.sh.
  • .github/workflows/upstream-sql-tests.yml: nightly, manual (input clickhouse_version), and on pull requests and pushes to main that change the harness or the workflow. 10 shards.
  • README.md, AGENTS.md (triage rules), CLAUDE.md (@AGENTS.md), and a one-line pointer in the root AGENTS.md.

Results

Upstream tests of v26.10.4.207, server 26.10.4.207 (stock image, CLICKHOUSE_SKIP_USER_SETUP=1):

  • Full sweep of all 12,961 .sql tests: 10,164 OK, 1,871 FAIL, 926 SKIPPED. Each failure has a cause: environment (cluster, ZooKeeper, S3, server configuration, clickhouse-client-only features, HTTP interface), client, or shim.
  • Allowlist: 10,193 tests run. No only= lines (one protocol).
  • Known failures: 631 tests in 26 groups: 329 tests in 22 client groups, 301 tests in 3 shim groups, 1 untriaged test. Each group header has the cause, a reproduction and Issue: not filed yet.
  • Three checks of the allowlist on a fresh server at -j 6 (more parallel than CI): 0 failures each, 28 to 34 minutes each.
  • CI: 10 round-robin shards at -j 4, about 1,020 tests each. The sum of the per-test times is about 155 minutes, which is about 44 minutes at -j 4 on one runner. In CI, each shard job takes about 5 minutes (4.6 to 4.8 minutes measured, with the set-up). No retry of failed tests: no known client bug makes random tests fail. The runner's own retries are off too (--dont_retry_failures).

Client bugs found

Not fixed in this PR, and no issues filed. The maintainers decide. Protocol: HTTP for all groups. In the reproductions, c = clickhouse_connect.get_client(host=..., session_id=...). "Expected" is the output of the server's TabSeparated and of clickhouse-client. Wrong value marks a group where the client gives a wrong value with no error.

  1. query-format-native (138 tests): Client.query removes the trailing ; and adds FORMAT Native. So statements of another dialect (KQL, PRQL), statements after SET implicit_select = 1, a SELECT with a trailing comma and EXPLAIN AST fail, and system.query_log shows the changed text.
    c.query("SELECT 1,") -> UNKNOWN_IDENTIFIER (expected 1). c.command("SET implicit_select = 1"); c.query("1 + 2") -> SYNTAX_ERROR (expected 3). c.query("EXPLAIN AST SELECT 1") -> InternalError (expected the AST).
  2. dt64-sub-microsecond (37), wrong value: DateTime64 with precision 7, 8 or 9 is cut to microseconds.
    c.query("SELECT toDateTime64('2019-09-16 19:20:12.345678910', 9, 'UTC')") -> 2019-09-16 19:20:12.345678 (expected ...12.345678910).
  3. date-outside-python-range (26): Date32 and DateTime64 values before the year 1 or after 9999-12-31 fail the whole result. Values near the limits in a time zone east of UTC give OverflowError.
    c.query("SELECT toDate32('0000-01-01')") -> ValueError (expected 0000-01-01).
  4. column-name-invalid-utf8 (25): a column name that is not valid UTF-8 fails the query.
    c.query("SELECT hex('\xAA')") -> UnicodeDecodeError (expected AA).
  5. dynamic-value-without-type (19), wrong value: Dynamic values come without their type. A Tuple, a JSON object and a Map all read as a dict, and DateTime64(P) loses P.
    c.query("SELECT CAST(tuple(42) AS Tuple(b Int64))::Dynamic") -> {'b': 42} (expected (42)).
  6. client-default-settings (16), wrong value: the client sends date_time_input_format = best_effort and cast_string_to_dynamic_use_inference = 1 with each request, so a SET of these settings in the session has no effect.
    c.command("SET date_time_input_format = 'basic'"); c.query("SELECT getSetting('date_time_input_format')") -> best_effort (expected basic). c.query("SELECT '[1, 2]'::Dynamic") -> Array(Int64) (expected String).
  7. query-text-invalid-utf8 (9): query text that is not valid UTF-8 cannot be sent. The query must be a str and is encoded as strict UTF-8; bytes give TypeError.
    SELECT hex('<the byte 0xFF>') -> UnicodeEncodeError (expected FF).
  8. query-routed-to-command (8), wrong value: Client.query sends CHECK, KILL and some other statements through command(). A result of more than one row comes back as one row of tab-separated text; an empty result comes back as one row of the request summary.
    c.query("CHECK TABLE t SETTINGS check_query_single_value_result = 0") on a table with 2 parts -> 1 row '1_1_1_0\t1\t\n2_2_2_0\t1\t' (expected 2 rows).
  9. time64-sub-microsecond (7), wrong value: Time64 with precision 7, 8 or 9 is cut to microseconds.
    c.query("SELECT toTime64('00:00:01.1234567', 7)") -> 00:00:01.123456 (expected 00:00:01.1234567).
  10. wait-end-of-query (6): Client.query sends wait_end_of_query = 1 by default. The server then buffers the result, and the ProfileEvents of the query change. A per-query settings={"wait_end_of_query": 0} removes it. A client-level get_client(settings={"wait_end_of_query": 0}) has no effect on the sync query(), but the async client uses it.
    After SYSTEM CLEAR MARK CACHE, c.query("SELECT sum(b) FROM t PREWHERE a < 5000") -> FileOpen 6 in system.query_log (expected 4, as over plain HTTP).
  11. type-aggregate-function (6): AggregateFunction(...) columns are not supported.
    c.query("SELECT sumState(1)") -> NotSupportedError.
  12. map-unhashable-key (6): a Map with an Array, Map or named Tuple key fails, because the Map becomes a dict. A plain Tuple key works.
    c.query("SELECT map([1], 2)") -> TypeError: unhashable type.
  13. json-leaf-and-object-path (5): JSON with a path that is both a value and the prefix of another path fails.
    c.query("""SELECT '{"a": 1, "a.b": 2}'::JSON""") -> TypeError (expected {"a":1,"a":{"b":2}}).
  14. type-json-shared-path (4): the type JSON(SHARED a UInt64) is not parsed.
    A column of that type -> InternalError: Unrecognized ClickHouse type base: aUInt64.
  15. native-format-settings (4): settings that change the Native output make the client read it wrong (output_format_native_encode_types_in_binary_format = 1, output_format_native_use_flattened_dynamic_and_json_serialization = 1).
    c.query("SELECT 1 SETTINGS output_format_native_encode_types_in_binary_format = 1") -> InternalError (expected 1).
  16. qbit-stride (3), wrong value: the third parameter of QBit is ignored.
    c.query("SELECT [1, 2, ..., 16]::QBit(Float32, 16, 8)") -> read as QBit(Float32, 16), wrong values (expected [1, 2, ..., 16]).
  17. qbit-int8 (3): QBit(Int8, N) is not supported.
    c.query("SELECT [1, -2]::QBit(Int8, 2)") -> ValueError: Unsupported QBit element type 'Int8'.
  18. string-invalid-utf8 (2), wrong value: a String value that is not valid UTF-8 comes back as its hex text.
    c.query("SELECT unhex('FF') AS x") -> 'ff' (expected the byte 0xFF).
  19. client-startup-queries (2): get_client runs SELECT 1 AS check and SELECT name, value, readonly FROM system.settings LIMIT 10000 in the client's database, so tests that count the rows of system.query_log of their database find them. clickhouse-client runs no such queries. Unlike Go, these queries do not run in the user's session.
    get_client(database=db), then SELECT count() FROM system.query_log WHERE current_database = db -> 3 rows (expected 1).
  20. map-duplicate-keys (1), wrong value: a Map with a duplicate key keeps only one entry. This is documented for the default dict format; the pairs format keeps them.
    c.query("SELECT map('a', 1, 'a', 2)") -> {'a': 2} (expected {'a':1,'a':2}).
  21. dynamic-shared-variant-raw-bytes (1), wrong value: a Dynamic value in the shared variant comes back as raw bytes.
    c.query("SELECT [1::Variant(String, UInt64)]::Dynamic(max_types = 0)") -> bytes (expected [1]).
  22. decimal-wider-than-precision (1), wrong value: a Decimal result with more digits than its precision is rounded.
    c.query("SELECT materialize(toDecimal128('0.42', 38)) + 21") -> 38 digits (expected 1.00305798474369219219752355409390731264).

Each client group has a live case in test_live.py that pins the wrong result. When a fix makes a case pass, its test fails, so that the group is checked again. The README tells how to move the tests back into the allowlist.

The bug classes that the Go harness found were also checked on purpose. These are not bugs in clickhouse-connect: DateTime64 outside 1677-09-21 .. 2262-04-11, null-map bytes other than 1, NULL in LowCardinality(Nullable(...)) in a named tuple, extremes = 1, the session for the whole invocation, an INSERT with no data, tuples in tuples, Nullable(Tuple), Int128 in a tuple, type names with backtick element names and Tuple(), and session_timezone.

Shim gaps

Tests that fail because of the shim, not the client:

  • shim-output-format (288): output formats other than the TabSeparated family and Null. clickhouse-client formats the result itself; the shim reads results with Client.query (Native) and writes only TabSeparated. It never passes the FORMAT clause to the server, because then the test checks only the transport.
  • shim-output-setting (11): settings that change the server text output (date_time_output_format, output_format_decimal_trailing_zeros, interval_output_format, format_tsv_null_representation, type_json_skip_null_typed_paths, and the setting that cuts the trailing zeros of DateTime64).
  • shim-kql-split (2): in KQL, let ...; <query> is one statement. It cannot be checked while query-format-native stands.

[untriaged] (1): 01017_uniqCombined_memory_usage exceeds max_memory_usage by about 0.1% only through clickhouse-connect.

Notes for reviewers

  • The root pytest tests of on_push.yml also collects the harness: its 212 unit tests run (about 1 s), and the live tests skip. This is on purpose: a client change that breaks the harness shows in that PR, and the harness workflow runs only on changes of the harness. Checked on Python 3.10. If you want the harness out of the main matrix, a collect_ignore in tests/conftest.py does it.
  • Behavior seen, not listed as a bug (0 tests fail): when the client has a database (get_client(database=...)), a USE through command() has no effect, because the client sends database=<its database> with each request. The shim follows USE with client.database = <db>.
  • Behavior seen in CI, not listed as a bug: when Python zoneinfo does not know a zone name, a column with that time zone raises ProgrammingError, but a session_timezone with that name (the X-ClickHouse-Timezone of the response) logs only a warning, and the values are read in the server time zone. SET session_timezone = 'Cuba'; SELECT toDateTime64(12345, 0) then gives 1970-01-01 03:25:45 (expected 1969-12-31 22:25:45). The system zoneinfo of Ubuntu 26.04 does not have such old names without tzdata-legacy, so the harness installs the tzdata extra.
  • The harness is not shipped: find_packages(exclude=["tests*"]) keeps it out of the sdist and the wheel. It is not user-facing, so there is no CHANGELOG entry.
  • ruff 0.15.8 (ruff format --check and ruff check on the on_push.yml paths) is clean. actionlint finds only the runner label ubuntu-26.04, which on_push.yml also uses.

Run locally

pip install "cython==3.2.5" "setuptools>=77.0.3" jinja2 pytest pytest-xdist
CLICKHOUSE_CONNECT_SKIP_CYTHON=1 pip install -e .
CLICKHOUSE_CONNECT_REQUIRE_C=1 python setup.py build_ext --inplace
docker run -d --name clickhouse-upstream-tests --hostname "$(hostname)" -p 8123:8123 -p 9000:9000 \
  -e CLICKHOUSE_SKIP_USER_SETUP=1 "clickhouse/clickhouse-server:$(tests/clickhouse-test-runner/scripts/pinned-version.sh)"
tests/clickhouse-test-runner/scripts/fetch-upstream.sh
tests/clickhouse-test-runner/scripts/run-upstream-tests.sh -j 8

Install, KNOWN_FAILURES=<id>, shards, the real-client run and how to grow the allowlist: tests/clickhouse-test-runner/README.md.

Checklist

  • Unit and integration tests covering the common scenarios were added (unit tests of the harness, and live tests against the server)

🤖 Generated with Claude Code


Note

Low Risk
Changes are isolated to test tooling and CI; core driver behavior is not modified, though the new workflow adds significant CI time and Docker dependency.

Overview
Adds tests/clickhouse-test-runner/, a harness that drives ClickHouse’s tests/clickhouse-test suite against clickhouse-connect via a clickhouse-client shim (HTTP, Native decode, TabSeparated rendering). It includes an allowlist (~10k passing tests, ~631 known failures in grouped comments), pinned server 26.10.4.207, fetch/run scripts, unit/live pytest, and maintainer docs (README.md, AGENTS.md).

Adds .github/workflows/upstream-sql-tests.yml: nightly, manual, and PR/push runs on a 10-shard matrix (Docker ClickHouse, build Cython in-place, run allowlist at -j 4; shard 1 also runs harness pytest). Updates root AGENTS.md to point agents at the harness docs.

Reviewed by Cursor Bugbot for commit 1df0743. Bugbot is set up for automated code reviews on this repo. Configure here.

…use-connect

tests/clickhouse-test-runner/ has a program that imitates clickhouse-client
well enough for tests/clickhouse-test of ClickHouse to drive it unchanged. It
runs each statement through get_client(), query() and command() in one HTTP
session and renders the values as TabSeparated text from the column types, so
the upstream .reference files check how clickhouse-connect reads each value.

- allowlist.txt: 10,193 tests that pass, and 631 known failures in 26 groups
  (22 client groups, 3 shim groups, 1 untriaged test).
- clickhouse-version pins the server and the upstream tests together
  (26.10.4.207).
- Scripts to get the upstream tests, to run the allowlist (shards,
  KNOWN_FAILURES) and to run the same tests through the real clickhouse-client.
- Unit tests, and live tests that compare the rendering with the server's own
  TabSeparated output.
- upstream-sql-tests.yml: nightly, manual and on changes of the harness, in 10
  shards.
- README.md, AGENTS.md with the triage rules, CLAUDE.md, and a pointer in the
  root AGENTS.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

AI review gate — Human approval in place of AI review

Approved on the head commit by joe-clickhouse (write access, not the author), standing in for the AI review:

  • Cursor Bugbot found issues that are not resolved (check concluded 'neutral').

What to do:

  • All of the reviewer's comment threads are resolved, but its check on this commit still reports issues. Post bugbot run as a new top-level PR comment for a fresh review, or push a commit.

Evaluated at 1df07438. This required workflow does not re-run on its own once the AI review later concludes — check the Cursor Bugbot check on this commit directly for its current state.

The system zoneinfo of the ubuntu-26.04 runner does not have old zone names
such as US/Samoa, Cuba, CET and Asia/Calcutta (Ubuntu moved them to
tzdata-legacy). Python zoneinfo then cannot resolve them, so six allowlisted
tests failed in CI: a column with such a time zone fails, and a value in such
a session_timezone is read in the server time zone. The tzdata package gives
zoneinfo all names. The README and AGENTS.md now say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@polyglotAI-bot
polyglotAI-bot marked this pull request as ready for review November 19, 2026 06:13
@polyglotAI-bot
polyglotAI-bot requested a review from a team as a code owner November 19, 2026 06:13
@security-ai-gate-reviewer

security-ai-gate-reviewer Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

AI review gate — auto-approval withheld

The AI review gate is green, but the approver did not approve 0fc39739: it changes paths that always require a human reviewer: .github/workflows/upstream-sql-tests.yml (commit 03113d9 has no verified signature; commit 03113d9 has no verified signature).

What to do: ask someone with write access who is not the PR author to approve this pull request.

History (latest 5 heads, newest first)

  • 0fc397395a35 withheld — it changes paths that always require a human reviewer: .github/workflows/upstream-sql-tests.yml (commit 03113d9 has no verified signature; commit 03113d9 has no verified signature)
  • 625f4f72a433 withheld — it changes paths that always require a human reviewer: .github/workflows/upstream-sql-tests.yml (commit 03113d9 has no verified signature; commit 03113d9 has no verified signature)
  • ef95bb9b6eb5 withheld — it changes paths that always require a human reviewer: .github/workflows/upstream-sql-tests.yml (commit 03113d9 has no verified signature; commit 03113d9 has no verified signature)

polyglotAI-bot and others added 4 commits November 19, 2026 13:31
- Turn off the runner's own retries (--dont_retry_failures), so that
  RETRY_FAILED is the only retry. Without the flag, the runner runs a
  failed test again when its output has one of its MESSAGES_TO_RETRY,
  and reports it as OK when it then passes.
- Write the header of TSVRaw formats without escapes, as the server
  does (TabSeparatedRowOutputFormat::writeLine).
- Skip heredocs when the shim finds the top-level words of a statement,
  as the splitter does.

No allowlist change: the 50 allowlisted tests that use a Raw format
with names or a heredoc pass, and the 8 known failures among them fail
for the same causes as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The program wrote its raw command line to CLICKHOUSE_CLIENT_CLI_LOG, so the
value of --password went into the file in clear. CI uploads that file as an
artifact when a shard fails, and GitHub masks secrets only in the console
output, not in artifacts. No CI run uses a password today.

The log now holds the arguments with the --password value replaced by ***.
The parser always takes the argument after --password as its value, so each
argument after a --password argument is hidden. A live test runs the program
with a unique password and checks that the log does not contain it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Generate the live test run id inside the tests and give the
  parametrized live tests explicit ids, so xdist workers collect the
  same tests on pytest 9.0
- Let a client fix pull request move its live pin and enable its
  allowlist group
- Correct the wait-end-of-query group: per-query settings override the
  default, a client-level value is ignored only by the sync query path
- Compare the wait-end-of-query FileOpen count with a plain HTTP run on
  the same server
- Remove the unused RETRY_FAILED retry loop, the only=<protocol>
  handling and two dead branches

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6503e71. Configure here.

…ness

parse_set_assignments and parse_use_database read the text after the
keyword without skipping comments. A comment in a SET became part of a
setting name or value, so the shim did not update dialect,
implicit_select or ignore_format_null_for_explain, and kept sending a
command-line setting that the SET had replaced. A comment that held a
quote also hid the assignments after it.

Both parsers now replace each comment with a space first (new
lexer.strip_comments; quoted strings, quoted identifiers and heredocs do
not change). USE DATABASE also accepts any whitespace before the name.

In the upstream tests of the pinned version, only
04277_parallel_replicas_join_dp_reorder (not in the allowlist) has a
comment in a SET or USE. The allowlist does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joe-clickhouse
joe-clickhouse merged commit d74e506 into main Nov 21, 2026
100 of 101 checks passed
@joe-clickhouse
joe-clickhouse deleted the polyglot/core-sql-tests branch November 21, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants