Repository navigation
Add a harness that runs the ClickHouse core SQL tests through clickhouse-connect - #1223
Conversation
…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>
AI review gate — Human approval in place of AI reviewApproved on the head commit by joe-clickhouse (write access, not the author), standing in for the AI review:
What to do:
Evaluated at |
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>
AI review gate — auto-approval withheldThe AI review gate is green, but the approver did not approve 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)
|
- 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
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ 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>

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.referencefiles are the oracle for how clickhouse-connect reads each value.Tracking issue: ClickHouse/integrations#809
How it works:
bin/clickhouseis a small program that imitatesclickhouse-clientwell enough fortests/clickhouse-testto drive it unchanged: the same flags, stdin and--query, test hints (serverError,clientError,echo), statement splitting asClientBase::executeMultiQuery, inlineINSERTdata, andextract-from-config.get_client(...)with onesession_idfor the whole invocation (soSET,USEand temporary tables last),query()for statements with a result,command()for the rest, command-line settings throughsettings=. The default C-accelerated decoding. No pandas, numpy or Arrow paths.result_rowsasTabSeparatedtext fromcolumn_types. It never passesFORMATto the server. Live tests compare its output with the server's ownFORMAT TSVoutput for many expressions.--portmaps toCLICKHOUSE_PORT_HTTP.Files:
clickhouse_test_runner/: the program (args,split,hint,lexer,render,runner,formats), anderrorcodes.py, whichscripts/fetch-upstream.shgenerates fromsrc/Common/ErrorCodes.cppof 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 tagv26.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 (inputclickhouse_version), and on pull requests and pushes tomainthat 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 rootAGENTS.md.Results
Upstream tests of v26.10.4.207, server 26.10.4.207 (stock image,
CLICKHOUSE_SKIP_USER_SETUP=1):.sqltests: 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.only=lines (one protocol).Issue: not filed yet.-j 6(more parallel than CI): 0 failures each, 28 to 34 minutes each.-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 4on 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'sTabSeparatedand ofclickhouse-client. Wrong value marks a group where the client gives a wrong value with no error.query-format-native(138 tests):Client.queryremoves the trailing;and addsFORMAT Native. So statements of another dialect (KQL, PRQL), statements afterSET implicit_select = 1, aSELECTwith a trailing comma andEXPLAIN ASTfail, andsystem.query_logshows the changed text.c.query("SELECT 1,")->UNKNOWN_IDENTIFIER(expected1).c.command("SET implicit_select = 1"); c.query("1 + 2")->SYNTAX_ERROR(expected3).c.query("EXPLAIN AST SELECT 1")->InternalError(expected the AST).dt64-sub-microsecond(37), wrong value:DateTime64with 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).date-outside-python-range(26):Date32andDateTime64values before the year 1 or after 9999-12-31 fail the whole result. Values near the limits in a time zone east of UTC giveOverflowError.c.query("SELECT toDate32('0000-01-01')")->ValueError(expected0000-01-01).column-name-invalid-utf8(25): a column name that is not valid UTF-8 fails the query.c.query("SELECT hex('\xAA')")->UnicodeDecodeError(expectedAA).dynamic-value-without-type(19), wrong value:Dynamicvalues come without their type. ATuple, a JSON object and aMapall read as adict, andDateTime64(P)losesP.c.query("SELECT CAST(tuple(42) AS Tuple(b Int64))::Dynamic")->{'b': 42}(expected(42)).client-default-settings(16), wrong value: the client sendsdate_time_input_format = best_effortandcast_string_to_dynamic_use_inference = 1with each request, so aSETof 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(expectedbasic).c.query("SELECT '[1, 2]'::Dynamic")->Array(Int64)(expectedString).query-text-invalid-utf8(9): query text that is not valid UTF-8 cannot be sent. The query must be astrand is encoded as strict UTF-8;bytesgiveTypeError.SELECT hex('<the byte 0xFF>')->UnicodeEncodeError(expectedFF).query-routed-to-command(8), wrong value:Client.querysendsCHECK,KILLand some other statements throughcommand(). 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).time64-sub-microsecond(7), wrong value:Time64with precision 7, 8 or 9 is cut to microseconds.c.query("SELECT toTime64('00:00:01.1234567', 7)")->00:00:01.123456(expected00:00:01.1234567).wait-end-of-query(6):Client.querysendswait_end_of_query = 1by default. The server then buffers the result, and the ProfileEvents of the query change. A per-querysettings={"wait_end_of_query": 0}removes it. A client-levelget_client(settings={"wait_end_of_query": 0})has no effect on the syncquery(), but the async client uses it.After
SYSTEM CLEAR MARK CACHE,c.query("SELECT sum(b) FROM t PREWHERE a < 5000")->FileOpen6 insystem.query_log(expected 4, as over plain HTTP).type-aggregate-function(6):AggregateFunction(...)columns are not supported.c.query("SELECT sumState(1)")->NotSupportedError.map-unhashable-key(6): aMapwith anArray,Mapor namedTuplekey fails, because theMapbecomes adict. A plainTuplekey works.c.query("SELECT map([1], 2)")->TypeError: unhashable type.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}}).type-json-shared-path(4): the typeJSON(SHARED a UInt64)is not parsed.A column of that type ->
InternalError: Unrecognized ClickHouse type base: aUInt64.native-format-settings(4): settings that change theNativeoutput 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(expected1).qbit-stride(3), wrong value: the third parameter ofQBitis ignored.c.query("SELECT [1, 2, ..., 16]::QBit(Float32, 16, 8)")-> read asQBit(Float32, 16), wrong values (expected[1, 2, ..., 16]).qbit-int8(3):QBit(Int8, N)is not supported.c.query("SELECT [1, -2]::QBit(Int8, 2)")->ValueError: Unsupported QBit element type 'Int8'.string-invalid-utf8(2), wrong value: aStringvalue that is not valid UTF-8 comes back as its hex text.c.query("SELECT unhex('FF') AS x")->'ff'(expected the byte 0xFF).client-startup-queries(2):get_clientrunsSELECT 1 AS checkandSELECT name, value, readonly FROM system.settings LIMIT 10000in the client's database, so tests that count the rows ofsystem.query_logof their database find them.clickhouse-clientruns no such queries. Unlike Go, these queries do not run in the user's session.get_client(database=db), thenSELECT count() FROM system.query_log WHERE current_database = db-> 3 rows (expected 1).map-duplicate-keys(1), wrong value: aMapwith a duplicate key keeps only one entry. This is documented for the defaultdictformat; thepairsformat keeps them.c.query("SELECT map('a', 1, 'a', 2)")->{'a': 2}(expected{'a':1,'a':2}).dynamic-shared-variant-raw-bytes(1), wrong value: aDynamicvalue in the shared variant comes back as raw bytes.c.query("SELECT [1::Variant(String, UInt64)]::Dynamic(max_types = 0)")->bytes(expected[1]).decimal-wider-than-precision(1), wrong value: aDecimalresult with more digits than its precision is rounded.c.query("SELECT materialize(toDecimal128('0.42', 38)) + 21")-> 38 digits (expected1.00305798474369219219752355409390731264).Each client group has a live case in
test_live.pythat 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:
DateTime64outside 1677-09-21 .. 2262-04-11, null-map bytes other than 1, NULL inLowCardinality(Nullable(...))in a named tuple,extremes = 1, the session for the whole invocation, anINSERTwith no data, tuples in tuples,Nullable(Tuple),Int128in a tuple, type names with backtick element names andTuple(), andsession_timezone.Shim gaps
Tests that fail because of the shim, not the client:
shim-output-format(288): output formats other than theTabSeparatedfamily andNull.clickhouse-clientformats the result itself; the shim reads results withClient.query(Native) and writes onlyTabSeparated. It never passes theFORMATclause 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 ofDateTime64).shim-kql-split(2): in KQL,let ...; <query>is one statement. It cannot be checked whilequery-format-nativestands.[untriaged](1):01017_uniqCombined_memory_usageexceedsmax_memory_usageby about 0.1% only through clickhouse-connect.Notes for reviewers
pytest testsofon_push.ymlalso 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, acollect_ignoreintests/conftest.pydoes it.get_client(database=...)), aUSEthroughcommand()has no effect, because the client sendsdatabase=<its database>with each request. The shim followsUSEwithclient.database = <db>.zoneinfodoes not know a zone name, a column with that time zone raisesProgrammingError, but asession_timezonewith that name (theX-ClickHouse-Timezoneof 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 gives1970-01-01 03:25:45(expected1969-12-31 22:25:45). The system zoneinfo of Ubuntu 26.04 does not have such old names withouttzdata-legacy, so the harness installs thetzdataextra.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 format --checkandruff checkon theon_push.ymlpaths) is clean. actionlint finds only the runner labelubuntu-26.04, whichon_push.ymlalso uses.Run locally
Install,
KNOWN_FAILURES=<id>, shards, the real-client run and how to grow the allowlist:tests/clickhouse-test-runner/README.md.Checklist
🤖 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’stests/clickhouse-testsuite against clickhouse-connect via aclickhouse-clientshim (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 rootAGENTS.mdto 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.