Repository navigation
Tests for the clickhouse_json dialect (follow-up to #100412) - #104456
alexey-milovidov merged 11 commits into
Conversation
…son_ast_dialect` Per @alexey-milovidov directive on ClickHouse#100412 (2026-05-07): "We should have tests for `allow_experimental_json_ast_dialect` and `dialect = 'clickhouse_json'`". Adds `tests/queries/0_stateless/04057_dialect_clickhouse_json.sh` covering: * Default values of both settings. * The experimental gate is checked at parse time, on both client-side TCP path (`ClientBase::parseQuery`) and server-side HTTP path (`executeQueryImpl`). With the gate off, both paths reject queries under `dialect = 'clickhouse_json'` with `SUPPORT_IS_DISABLED` and the error message points to the gate setting. * Hand-written JSON-AST execution (`SELECT 1`). * Round-trip via `parseQueryToJSON`: the JSON output of common SQL shapes (arithmetic, aliases, `FROM numbers` + `WHERE`/`ORDER BY`, `GROUP BY` + aggregates) is submitted under the dialect and produces the same result as the SQL form. * Server-side escape hatch: a query starting with `SET` is parsed as plain SQL even under `dialect = 'clickhouse_json'`, so users can switch the dialect back without sending a JSON-AST `SET`. * Error paths: malformed JSON, empty `{}`, and unknown `type` all raise `BAD_ARGUMENTS`. Verified locally: 50/50 passes with full random settings. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Pre-PR validation gate (per
Session: |
|
cc @alexey-milovidov @evillique — could you review this? Test-only follow-up to #100412 covering both the experimental gate |
|
Workflow [PR], commit [4d00cda] Summary: ✅ AI ReviewSummaryThis PR adds and tightens the stateless Final Verdict✅ Approved |
Per `clickhouse-gh[bot]` review on PR ClickHouse#104456: > This script relies on several `grep ... | head ...` pipelines to assert > specific error markers, but it never enables `pipefail`. Without > `pipefail`, these pipelines return the status of `head`, so a missing > match in `grep` still exits successfully and the test can pass while > silently skipping the intended assertion. Please add `set -euo pipefail` > near the top (or at least `set -o pipefail`) so missing matches fail > the test deterministically. Adds `set -euo pipefail` near the top of the script. The six pipelines that submit a query expected to fail (gate-off, malformed JSON, empty object, unknown AST type) are wrapped in `{ ... || true; } |` so `set -e` does not exit on the expected non-zero status of `clickhouse-client` / `clickhouse-curl`; the `|| true` only neutralises the leftmost producer's exit code, while `pipefail` still surfaces a `grep` no-match as a non-zero pipeline status (which then propagates via `set -e`). Verified locally: - `bash -n` syntax check passes. - Stub-based simulation of the full script under `set -euo pipefail` produces the same output as the previous unguarded version (script exits 0, no early termination). - Negative test confirmed that a `grep` with no match aborts the script via `set -e + pipefail` (the line after the failing pipeline is not executed). - `tests/queries/shell_config.sh` is fully compatible with `set -u` thanks to its `${VAR:-}` expansions. PR: ClickHouse#104456 Bot review: ClickHouse#104456 (comment) (approx.)
|
Bot pipefail concern addressed in 79540a6. The fix adds Verified locally:
CI on #104456 is still expected to be RED until #100412 lands, by design — the test references settings ( Session: cron:clickhouse-ci-task-worker:20260509-154500 |
|
I didn't ask for this; that comment was for myself. But we can merge this PR into the branch of #100412. |
|
Dear @groeneai, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
CI finish ledger - 75a2d9fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260729-170000 |
…clickhouse-json-dialect-clean
The reviewer noted that with the gate on, the only HTTP request in `04057_dialect_clickhouse_json.sh` was the plain-SQL `SET` escape hatch, so a regression in the `clickhouse_json` branch of `executeQueryImpl` - in particular in its `BAD_ARGUMENTS` validation - could leave the test green. The objection was previously declined only because `dialect = 'clickhouse_json'` did not exist on `master`; now that ClickHouse#100412 has been merged, the coverage can be added here. Four gate-on HTTP requests are added: a round-trip `parseQueryToJSON` body that must execute, and malformed JSON, an empty object and an unknown `type`, which must each be rejected server-side with `BAD_ARGUMENTS`. The three error bodies are rejected by the client's own parse in the existing cases, so they never reached the server's validation before. The whole test passes locally against `master` (6/6 runs with randomized settings, plus the new cases 3/3).
…clickhouse_json` The test proved that `SET` stays a plain-SQL escape hatch under `dialect = 'clickhouse_json'`, but not the complementary invariant: that nothing else does. A regression that broadened the escape hatch, or fell back from the JSON-AST parser to the SQL parser, would have left the test green. Two gate-on negative cases are added, one over `clickhouse-client` and one over HTTP, each asserting both halves - that `SELECT 1` submitted as plain SQL is rejected with `BAD_ARGUMENTS`, and that it did not execute as SQL anyway (no `1` in the output). Negative control: dropping `dialect = 'clickhouse_json'` from the client call - a stand-in for a SQL-fallback regression - flips the output to `NO_ERROR` / `SQL_FALLBACK`, so the assertions bite. The whole test passes 3/3 locally against `master` with randomized settings.
CI finish ledger — e75fc81Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
This is the only failure on this head. Fix-presence probe for the owner, by content rather than commit distance: this head's Gates: (a) 175 check-runs, 0 queued/in_progress/pending/waiting; (b) Session id: cron:our-pr-ci-monitor:20260806-050000 |
…/tests-for-clickhouse-json-dialect-clean
The setting was renamed from `allow_experimental_json_ast_dialect` to `enable_json_ast_dialect` by 3a5c031, after this branch was cut. The old name is not an alias, so on current master `SET allow_experimental_json_ast_dialect = 1` is `UNKNOWN_SETTING` and the gate-off error message names the new setting instead of the old one. The branch CI stayed green because it built a server from a base that predates the rename. The merge queue tests the PR merged into current master, where the assertion that the error message names the setting found no match, `grep` exited 1, and `set -euo pipefail` aborted the script before the remaining assertions ran: 20 of 20 runs failed in `Stateless tests (amd_binary, flaky check)` with `return code: 1`. Renames the 18 uses in the `.sh` and the 2 in the `.reference`. The two `system.settings` rows also swap, because the assertion orders by name and `dialect` sorts before `enable_json_ast_dialect` where it sorted after `allow_experimental_json_ast_dialect`. No assertion is removed, weakened or added, and no pipeline shape changes. Also drops the header's claim that a non-zero pipeline status merely produces a reference mismatch. Under `set -e` with `pipefail` it terminates the script, which is why this failure surfaced as an abort rather than a diff. Co-Authored-By: Claude Fable 5 <[email protected]>
The test carried a bare `# Tags: no-fasttest` with no reason. clickhouse-test returns FailureReason.FAST_ONLY for such a test when `--fast-tests-only` is passed, so the Fast test job never executed it: CIDB over 20 days shows `Fast test` SKIPPED 9 and `Fast test (arm_darwin)` SKIPPED 2, with no OK or FAIL row in either. The tag arrived in this PR's own first commit, so the coverage this PR adds was suppressed in the job that gates nearly every PR. Measured rather than assumed before removing it. Built a Fast-test-shaped binary with the flags from ci/jobs/fast_test.py (notably ENABLE_LIBRARIES=0, which is the usual reason a test needs this tag; the resulting server reports USE_PARQUET, USE_ORC, USE_AVRO, USE_ARROW and USE_HDFS all empty) and ran the test against it under the job's own flag set. With the tag present the verdict is SKIPPED; with it removed the verdict is OK, ten times out of ten, and a direct run of the script matches the reference byte for byte over all 53 lines with empty stderr. The test only uses clickhouse-client, the HTTP interface and shell builtins, so nothing it touches depends on the disabled libraries. The 50x flaky-check equivalent still passes 50 of 50 on the ordinary debug build, and eight concurrent copies pass, so no parallelism tag is needed.
…tokens The five client-side cases retained only tokens the server emits identically for the same input, so they did not observe which path produced them. The client forwards the original JSON text (pinOutboundDialectForJSONDialect) and the wire carries query text, so the server re-parses the same bytes through the same IAST::createFromJSON and throws the same codes. A regression in which the client stopped validating and simply forwarded the body would have printed byte-identical output. The file's own HTTP arms already assert those exact tokens, which shows the client-side expected lines were satisfiable by the server alone. Each of the five cases now also reports whether the error came from the client or from the server, using the prefix Client::processError prints only for a server exception. The check is written as an absence test so it does not hard-code the version string. Every previously expected line is unchanged; this only adds one line per case. Measured with a temporary client mutation that skips validation for bodies that still look like JSON on the wire, which is the subset where the server produces identical tokens: the pre-change file stays green with byte-identical output, confirming those assertions were blind, and the post-change file fails with FROM_SERVER where from_client is expected. Also 50 of 50 randomized runs green, 10 of 10 green under the Fast test job flag set on a build configured with ENABLE_LIBRARIES=0, byte-exact output against the reference with empty stderr, and 8 concurrent copies green. The assertion uses a here-string rather than a pipe into grep: with pipefail, a pipe into grep -q lets the writer take SIGPIPE once the output exceeds the pipe buffer, and the condition then silently takes the wrong branch. Measured for a matching input at 64 KiB and above.
Internal second-model review (click to expand)Three review rounds. Final round: 0 blockers, 0 majors, 0 findings from the second model. Fixed during review, both raised and resolved before this update: ❌ The test carried a bare ❌ The five client-side error cases asserted only tokens the server emits identically for the same input, so they did not observe which parse path produced them. The client forwards the original JSON text and the wire carries query text, so the server re-parses the same bytes through the same
💡 Noted, not changed: the file keeps Validation: 50/50 runs green with randomized settings against 20/20 failures in the merge queue, 10/10 under the Fast test job's own flag set, byte-exact output with empty stderr, 8 concurrent copies green. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260809-224200 |
|
cc @alexey-milovidov, the merge-queue blocker is fixed, so this is ready to re-queue. The test named |
…on its plain-SQL arm The gate-off message exists as two independent literals, in ClientBase::parseQuery and in executeQueryImpl. Only the client-side arm asserted that it names enable_json_ast_dialect, so a rename touching just the server copy left the HTTP arm green. That is the same drift class that turned this test red 20 of 20 in the merge queue when the setting was renamed from allow_experimental_json_ast_dialect, so the HTTP arm now captures the body and asserts the name too. The gate-on plain-SQL client arm asserted only that the request was rejected and did not execute as SQL. The server emits the same BAD_ARGUMENTS for the same body, so if the client stopped enforcing JSON-only input and forwarded the raw text still pinned to clickhouse_json, that arm stayed green while the client path it names was bypassed. It now carries the same "Received exception from server" absence check its five sibling client-side cases use. Both new assertions were verified to redden, each against a separate mutation of the code path it covers, with the pre-change file staying green in both arms (so the old assertions were provably blind) and each mutation reddening only its own line. Mutations reverted, source re-diffed identical, and the mutation symbols confirmed absent from the final binary. 50/50 randomized runs OK, 8 concurrent copies OK, direct run byte-exact with no stderr.
|
Pushed 4d00cda after your approval, which outdates it: two additive assertions from the AI reviewer, test files only. The gate-off message exists as two separate literals (client and server), and only the client arm asserted it names the setting, so a rename touching just the server copy would not have reddened. That is exactly what broke this test in the queue, so the HTTP arm now asserts the name too. The other arm gained the provenance check its five siblings already had. Each was verified to redden against a mutation of the path it covers, with the pre-change file green in both. Ready to re-queue. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
CI finish ledger - 4d00cdaEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CI is fully finished on this head with zero failing checks. The four
On the reduced job matrix: this PR changes only two files, both under Session id: cron:our-pr-ci-monitor:20260810-063000 |
Related: #100412
Per @ alexey-milovidov's directive on #100412: "We should have tests for
allow_experimental_json_ast_dialectanddialect = 'clickhouse_json'". The gate was since renamed toenable_json_ast_dialectby 3a5c031, and this test uses the current name.This adds
tests/queries/0_stateless/04057_dialect_clickhouse_json.sh, exercising both the client-side (ClientBase::parseQuery) and server-side (executeQueryImpl) parse paths added in #100412. Coverage:enable_json_ast_dialectis0,dialectisclickhouse.SUPPORT_IS_DISABLED, and the message names the setting to enable.SELECT 1executes, andparseQueryToJSONround-trips (arithmetic, aliases,FROM numberswithWHERE/ORDER BY,GROUP BYwith aggregates) return the same result as the SQL form.typeare each rejected withBAD_ARGUMENTS. The client rejects those bodies itself in the client-side cases, so this is the only place the server's validation is asserted.SETescape hatch: under the dialect a query starting withSETis still parsed as plain SQL, so the dialect can be switched back. Anything else is rejected, and is asserted not to have executed as SQL anyway.{}and unknowntypeall raiseBAD_ARGUMENTS, and each asserts the error came from the client's own parse, since the server emits the same code for the same body.The test complements
04212_clickhouse_json_dialect_gate.shand04347_ast_json_http_dialect_trailing_semicolon.sh, which came in with #100412.Two later commits drop a bare
# Tags: no-fasttestthat had suppressed this coverage in the Fast test job (verified against a Fast-test-shaped build first), and add the provenance assertions above. 50/50 runs green with randomized settings, 10/10 under the Fast test job's flag set.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...