Skip to content

test: run ClickHouse core SQL tests through clickhouse-go - #2141

Merged
ccoltx merged 30 commits into
mainfrom
ccoltx/Run-core-SQL-tests
Nov 24, 2026
Merged

ccoltx merged 30 commits into
mainfrom
ccoltx/Run-core-SQL-tests

Conversation

@ccoltx

@ccoltx ccoltx commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Runs a curated subset of the ClickHouse core SQL tests (tests/queries/0_stateless) through clickhouse-go, nightly and on changes to the harness. Implements ClickHouse/integrations#810.

tests/clickhouse-test-runner/ is a Go program that imitates clickhouse-client well enough for the upstream runner (tests/clickhouse-test) to drive it without changes. It sends every query through clickhouse-go, over the native or the HTTP protocol. It scans each row into ColumnType.ScanType(), as a user does, and writes the values as TabSeparated. So a test passes only when clickhouse-go decodes and scans every value correctly; the upstream .reference files are the oracle.

The goal is to find client bugs, not only to pass tests. The harness already found several (see below).

What is in the PR

  • The program: argument parsing, statement splitting (same-line trailing hints, echo hints, the Tags: header, INSERT ... FORMAT inline data), test hints, session handling over both protocols, and a type-directed TabSeparated renderer that is checked against the server's own output.
  • allowlist.txt: 9,903 tests over both protocols, 129 over native only (WITH TOTALS: the server sends no totals in the HTTP Native output), and 920 known failures in 30 groups. Each group header gives the cause and a small reproduction. KNOWN_FAILURES=<id> runs one group, to check a fix.
  • clickhouse-version: pins the server version and the upstream tests together (26.10.4.207, tests from v26.10.4.207-stable). A new ClickHouse release does not change CI; a bump is a pull request of its own, so other pull requests do not fail because of a release.
  • upstream-sql-tests.yml: nightly, manual (clickhouse_version input to try a version), and on pull requests that change the harness. Native and HTTP, 8 shards each.
  • README.md and AGENTS.md: local runs, how to find the cause of a failure (compare with the real clickhouse-client: scripts/run-with-real-client.sh), the rules for the allowlist, and how to bump the version. tests/clickhouse-test-runner/CLAUDE.md imports AGENTS.md, and the root .claude/CLAUDE.md points to it.

Client bugs that the harness found

All reproduce with the public API only, over both protocols unless noted. None is fixed in this PR; each has a known-failure group. I have not filed issues yet.

Wrong values, no error:

  • DateTime64 outside 1677-09-21 .. 2262-04-11 is wrong when read and when written (int64 nanosecond overflow in ch-go DateTime64.Time and in timeToInt64).
  • Time64 with precision 4, 5, 7 or 8 is cut to milliseconds (ch-go truncateDuration).
  • A Nullable value with a null-map byte other than 1 reads as not NULL (lib/column/nullable.go checks == 1).
  • A NULL in a LowCardinality(Nullable(String)) element of a named tuple reads as "".
  • With extremes = 1, native Rows gives the extremes as data rows.

Session state, native:

  • The pool can open a second connection with MaxOpenConns: 1, without an error, so the session state is lost: release() frees the slot before it returns the connection to the idle list. About 1 to 5 in 2,000 iterations. This can make the nightly run fail intermittently in tests with SET, until it is fixed.
  • The connection closes after any error, also a server exception, so temporary tables are lost.
  • Exec of an INSERT that needs data from the client (INSERT INTO t VALUES) never returns; it waits until the context ends.
  • Query on a statement with no result block (WITH ... INSERT) returns io.EOF and closes the connection.
  • rows.Next() can drop blocks that it received before an exception: it reads the block and error channels in one select, so the error can win (in 4 of 20 runs, 970 or 990 of 1000 rows).

Errors on valid data: a tuple in a tuple, Nullable(Tuple) and Int128 in a tuple cannot be scanned into ScanType(); backtick-quoted tuple element names, some JSON data (stream out of sync), JSON(SHARED ...), some QBit forms, Map keys of type Array/Map/Tuple, Tuple(), AggregateFunction, Geometry. Over HTTP, the server-info query of a new connection runs in the user session (visible in query_log; breaks a session with SET dialect). session_timezone is ignored.

Test plan

  • Unit tests of the harness (go test ./tests/clickhouse-test-runner/), and live tests that compare the renderer with the server's TabSeparated output (CLICKHOUSE_TEST_RUNNER_LIVE=1, run in CI shard 1).
  • Locally against 26.10.4.207: full sweeps of all 12,961 .sql tests over both protocols, with each failure compared against the real clickhouse-client. Then the allowlist three times on a fresh server per protocol: 0 to 9 failures per run, each one triaged (pool race, test isolation, or memory limits that also fail through the real client).
  • This PR runs the new workflow on CI.

Checklist

  • Unit and integration tests covering the common scenarios were added

🤖 Generated with Claude Code


Note

Low Risk
Changes are confined to test tooling, CI, and docs; the driver library behavior is exercised but not modified in this PR.

Overview
Adds tests/clickhouse-test-runner, a Go clickhouse-client shim that drives upstream tests/clickhouse-test while executing queries via clickhouse-go (native or HTTP), scanning with ColumnType.ScanType(), and rendering results as TabSeparated for comparison with upstream .reference files.

The harness includes statement splitting, test hints/error codes, session handling (including HTTP session_id and native reconnect after errors), FORMAT-clause handling, and a type-directed renderer with unit and optional live server tests. allowlist.txt (per PR description), clickhouse-version pin (26.10.4.207), and scripts fetch upstream tests, shard runs, and optionally retry flaky native SET failures.

.github/workflows/upstream-sql-tests.yml runs the allowlist on a schedule, on harness changes, and via manual dispatch (8 shards × native/http). AGENTS.md / README.md document triage rules; root .claude/CLAUDE.md points agents at AGENTS.md before editing the allowlist.

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

Add tests/clickhouse-test-runner: a Go program that imitates
clickhouse-client well enough for the upstream runner
(tests/clickhouse-test) to drive it. It runs every query through
clickhouse-go over the native or HTTP protocol, scans each row into
ColumnType.ScanType(), and writes the values as TabSeparated, so the
upstream .reference files check the decoding of the driver.

- allowlist.txt: 9,903 tests over both protocols, 129 over native only,
  and 920 known failures in 30 groups (client bugs and shim gaps), each
  with a reproduction.
- clickhouse-version pins the server version and the upstream tests
  together; a bump is an explicit pull request.
- upstream-sql-tests.yml: nightly, manual, and on changes to the
  harness; native and HTTP, 8 shards each.
- README.md and AGENTS.md describe local runs, the triage rules, how to
  grow the allowlist, and how to bump the version.

Refs ClickHouse/integrations#810

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccoltx
ccoltx requested review from a team, kavirajk and polyglotAI-bot as code owners November 18, 2026 06:23
Comment thread tests/clickhouse-test-runner/runner.go Resolved
Comment thread tests/clickhouse-test-runner/format.go Resolved
@polyglotAI-bot

polyglotAI-bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary
Adds a pinned upstream SQL harness for clickhouse-go's native API over TCP and HTTP. All findings of the earlier reviews are fixed or dropped.

Final verdict

✅ No open findings from Polyglot AI. The two Majors of the review of 6e576c8 are dropped after the author's reply (see their threads).

Updated by Polyglot AI for 6e576c8, on request of the PR author. A maintainer can ask for a new review by mentioning @polyglotAI-bot or requesting a review from it.

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes requested in the review of 77a0c5f: see the summary comment and the inline threads.

@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.

Stale Bugbot comment from a previous run.

Comment thread tests/clickhouse-test-runner/format.go Resolved
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

AI review gate — AI review passed

Clean review from: Cursor Bugbot.

- Split the test selector into several arguments of at most 64 KiB.
  Linux limits one argument to 128 KiB, and one selector for the full
  allowlist is about 360 KB, so a run with one shard failed with
  "Argument list too long". Both run scripts share selectors.sh now.
- Read FORMAT as the output-format clause only where it can be one: at
  the end of a query, before an optional SETTINGS clause, and for an
  INSERT only before any SELECT. `SELECT format FROM t` was read as an
  unsupported format, and `INSERT ... SELECT format ...` could take the
  rest of the script as inline data.

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

@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.

Stale Bugbot comment from a previous run.

Comment thread tests/clickhouse-test-runner/split.go Resolved
Comment thread tests/clickhouse-test-runner/split.go Resolved
ccoltx and others added 2 commits November 18, 2026 07:47
- Treat only the bare io.EOF sentinel (ServerEndOfStream) as a statement
  without a result. clickhouse-go wraps read failures, such as a
  disconnect or a truncated block, with %w, and errors.Is matched those
  too: a failed query could then look like an empty result.
- hasWord skips ClickHouse `# ` and `#!` comments, as the splitter does.
- Tests for aliases and columns named `format`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SELECT check of the last commit also rejected
`INSERT ... SELECT ... FROM input(...) FORMAT TSV`, which has inline
data. Instead, read the word after FORMAT: a SQL keyword (FROM, WHERE,
AS, ...) shows an identifier named `format`; any other word is a format
name. hasWord is not used anymore.

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

@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.

Stale Bugbot comment from a previous run.

Comment thread tests/clickhouse-test-runner/split.go Resolved

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes requested in the review of b71abce: see the summary comment and the inline threads.

- A query: a clause keyword after FORMAT (ASC, DESC, ...) shows an
  identifier, so `SELECT 1 AS format ORDER BY format DESC` is not a
  FORMAT DESC clause.
- An INSERT ... SELECT: the FORMAT clause comes after the top-level FROM
  of the SELECT. Before it, `format` is in the select list
  (`SELECT format x FROM s`, `SELECT format DIV 2 FROM s`). GLOBAL, DIV,
  MOD and other operator words are clause keywords too.
- Unit tests for these cases, and live tests that compare the queries
  with the server over both protocols.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@security-ai-gate-reviewer

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

Copy link
Copy Markdown

AI review gate — auto-approval withheld

The AI review gate is green, but the approver did not approve 61e1bccd: it changes paths that always require a human reviewer: .github/workflows/upstream-sql-tests.yml (commit 77a0c5f has no verified signature; commit 77a0c5f 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)

  • 61e1bccda8ff withheld — it changes paths that always require a human reviewer: .github/workflows/upstream-sql-tests.yml (commit 77a0c5f has no verified signature; commit 77a0c5f has no verified signature)
  • 7402883a2187 withheld — it changes paths that always require a human reviewer: .github/workflows/upstream-sql-tests.yml (commit 77a0c5f has no verified signature; commit 77a0c5f has no verified signature)
  • 30b9eb86a2de withheld — it changes paths that always require a human reviewer: .github/workflows/upstream-sql-tests.yml (commit 77a0c5f has no verified signature; commit 77a0c5f has no verified signature)
  • 54b10c0700db withheld — it changes paths that always require a human reviewer: .github/workflows/upstream-sql-tests.yml (commit 77a0c5f has no verified signature; commit 77a0c5f has no verified signature)
  • 56fdaf2c8273 withheld — it changes paths that always require a human reviewer: .github/workflows/upstream-sql-tests.yml (commit 77a0c5f has no verified signature; commit 77a0c5f has no verified signature)

ccoltx and others added 3 commits November 18, 2026 15:57
A known client bug (the pool race, [native-pool-race-new-connection] in
allowlist.txt) makes random tests with SET fail now and then over the
native protocol: about 40 of 10,000 tests per CI run, a different set
each time. With RETRY_FAILED_ONCE=1, the run script runs the failed
tests once more. A test that passes on the second run is a warning; a
test that fails twice fails the job. CI sets it; local runs that grow or
check the allowlist do not.

Move five tests that fail on almost every CI run into their
known-failure groups: three hit the pool race at the same point each
time, and two hit the HTTP server-hello bug in a LogsQL session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sixteen tests failed in two or more of five CI runs, or twice in one run
with the retry. They hit the pool race ([native-pool-race-new-connection])
too often for a retry to keep CI stable, so they move into that group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With about 40 race victims per native run, one retry was not enough:
now and then one victim is hit twice (05218_join_use_nulls_lc_key_full_sorting_merge
failed at two different points, both with join_use_nulls lost). The run
script now takes RETRY_FAILED=<n> (CI: 2). A test that passes on a retry
is a warning; a test that fails on every attempt fails the job.

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

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes requested in the review of f0c36b2: see the summary comment and the inline threads.

`SELECT 1 AS format, format x` was read as the clause `FORMAT x`. A
FORMAT clause follows a complete query; when the text before the word
ends with a comma, an opening parenthesis, an operator or a keyword such
as SELECT, the word starts an expression, so it is an identifier. The
same check applies to INSERT inline data.

Over all 190,722 statements of the allowlisted tests, the old and the new
parser give the same result.

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

@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.

Stale Bugbot comment from a previous run.

Comment thread tests/clickhouse-test-runner/split.go Resolved
…t-star

startsExpression looked back through whitespace only, so a FORMAT clause
after a block comment (`*/`) or after a select-star (`SELECT * FORMAT
TSV`, `FROM t SELECT * FORMAT TSV`) was read as an identifier. It now
takes the last significant token before the word, outside comments and
quotes. A `*` after SELECT, DISTINCT, a comma, `(` or `.` is a
select-star, which can end a query; another `*` multiplies.

Over all 190,722 statements of the allowlisted tests, the parser gives
the same result as before.

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

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes requested in the review of 9381219: see the summary comment and the inline threads.

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes requested in the review of 56fdaf2: see the summary comment and the inline threads.

The live test expected exactly three rows before the exception, but the
server decides how many blocks it sends first (it can squash small
blocks, and over HTTP it buffers the response), so the test could fail
intermittently with a correct shim. The behavior to check is the shim's:
it writes every row that it received before the error. writerows_test.go
checks that with a fake driver.Rows, with no server and no timing. With
the old writeRows, the test gets an empty output.

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

ccoltx commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

@polyglotAI-bot the Major of your review of 56fdaf2 (the late-error live test depends on scheduling) is fixed in 54b10c07: the live test is gone. The server decides how many blocks it sends before the exception, so the shim's own behavior (it writes every row it received before the error) is now checked by a unit test with a fake driver.Rows, in writerows_test.go, with no server and no timing. With the old writeRows, that test gets an empty output. Please review again.

Comment thread tests/clickhouse-test-runner/runner.go Resolved

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes requested in the review of 54b10c0: see the summary comment and the inline threads.

- parseUseDatabase could not read `USE /* c */ db`, so the shim stopped
  after the server had run the statement. Comments outside quotes are now
  dropped before the name is read, as for SET.
- The rows-before-error check runs over both protocols again. The server
  decides how many blocks it sends before the exception, and over native
  clickhouse-go can drop some of them (see below), so the live test needs
  some rows, all of them the values of the query, then the next
  statement. writerows_test.go still checks the exact output.
- New known-failure group [native-rows-dropped-before-error]: rows.Next()
  reads the block and error channels in one select, so an error can win
  over blocks that were already received. With the public API, 4 of 20
  runs of a query that fails after 1000 rows gave 970 or 990 rows. No
  allowlisted test is known to fail because of it.

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

ccoltx commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

@polyglotAI-bot both Majors of your review of 54b10c0 are addressed in 30b9eb86:

  • USE /* c */ db: parseUseDatabase drops comments outside quotes before it reads the name, as parseSetAssignments does. Unit tests, and a live test over native and HTTP (USE /* c */ system; SELECT currentDatabase();).
  • Rows before a stream error: the check runs over both protocols again (TestLiveRowsBeforeStreamError), and writerows_test.go keeps the exact check. The live test needs some rows, all of them the values of the query, then the next statement. It cannot need an exact count: the server decides how many blocks it sends before the exception, and over native clickhouse-go itself can drop received blocks. rows.Next() reads the block and error channels in one select, so an error can win over blocks already in the channel; with the public API, 4 of 20 runs of a query that fails after 1000 rows gave 970 or 990 rows. That is now the known-failure group [native-rows-dropped-before-error] in allowlist.txt.

Please review again.

Comment thread tests/clickhouse-test-runner/split.go Resolved

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes requested in the review of 30b9eb8: see the summary comment and the inline threads.

Over HTTP, the server can buffer the response and send only the
exception, so zero rows before the error is a correct result there. The
live test now needs at least one row over native only; over both
protocols, every row must be a value of the query, followed by the next
statement.

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

ccoltx commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

@polyglotAI-bot about the three Majors of your review of 30b9eb8:

  1. split.go:61, multiline trailing comments: no change, because the shim does what clickhouse-client does. The client also cuts at the first line break after the ;, inside the comment. Checked against clickhouse-client 26.10.4.207 with SELECT 1; /* a\nb */ SELECT 2;: the client prints 1, then fails with Syntax error: failed at position 1 (b): b */ SELECT 2;. The shim gives the same output and the same error (also for /* a\nb */\nSELECT 2; and /* x */ /* y\nz */ SELECT 2;). The .reference files come from that client, so a shim that splits differently would not match them.
  2. live_test.go:243, HTTP rows before a buffered exception: fixed in 7402883a. Over HTTP, zero rows before the error is accepted; over native, at least one row is still needed. Every row must be a value of the query, followed by the next statement.
  3. writerows_test.go, driver mocks: no change. The rule in .claude/CLAUDE.md is "Do not introduce an interface solely to enable test mocking". This test introduces no interface: it implements the public driver.Rows to check the shim's own output. The live test covers both protocols, and it cannot check an exact count: the server decides the blocks before the exception, and over native the driver can drop received blocks ([native-rows-dropped-before-error]). Your review of 56fdaf2 rejected a live test with an exact count for that reason, so the exact check stays deterministic, in the unit test.

Please review again.

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes requested in the review of 7402883: see the summary comment and the inline threads.

@ccoltx
ccoltx dismissed polyglotAI-bot’s stale review November 23, 2026 21:14

PolyglotAI and I are going in circles. Is finding has been refuted a few times, but it's unable to see that.

@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 1 potential issue.

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 6e576c8. Configure here.

Comment thread tests/clickhouse-test-runner/split.go Resolved

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes requested in the review of 6e576c8: see the summary comment and the inline threads.

@polyglotAI-bot
polyglotAI-bot dismissed stale reviews from themself November 24, 2026 06:20

Both Majors of the review of 6e576c8 are dropped: see the replies in their threads.

As the server parser (`ParserInsertQuery`) does, the splitter now skips
comments between `FORMAT` and the format name, and accepts a quoted
format name (`FORMAT "CSV"`). Before, such an `INSERT` was split as a
normal query, so a `;` in its inline data ended the statement.

A comment after the format name stays data: the server starts the data
right after the name, and clickhouse-client does the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccoltx
ccoltx merged commit 0ee2fd1 into main Nov 24, 2026
32 checks passed
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.

3 participants