Add formatExplainJSON exporter for ClickHouse EXPLAIN AST json = 1 with vendored reference suite#26
Draft
Copilot wants to merge 2 commits into
Draft
Add formatExplainJSON exporter for ClickHouse EXPLAIN AST json = 1 with vendored reference suite#26Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
…x in AST; vendor AST JSON corpus
Copilot created this pull request from a session on behalf of
peter-leonov-ch
June 14, 2026 12:50
View session
|
|
Collaborator
|
This is a result of the core agent having a little back and forth with this repo agent on the best strategy for AST sync. Most of the changes on the core agent made sense to me. Not sure (yet) about the changes to this repo. This is the partner PR to my fork of core: peter-leonov-ch/ClickHouse#1 |
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.
Implements Phases 1–3 of the JSON-AST plan: vendor the
EXPLAIN AST json = 1fixture corpus from the upstream ClickHouse PR (peter-leonov-ch/ClickHouse#1), implement an exporter converting this library's AST to that v1 JSON contract, and add a reference test suite plus debug tooling.Vendored reference corpus
tests/clickhouse-reference-ast-json/cases/— the 41 SQL → JSON pairs from the upstream PR, pinned at commitad33aa4ceba52f42afb17246cc2778d3733cfb7e. README records the source PR, SHA, format version, and snapshot caveats (fixtures at that SHA are bare AST nodes with native 64-bit numbers).npm run generate:ast-json-fixtures,explain:ch --json, and aCLICKHOUSE_IMAGEoverride indocker-compose.yml. Until then the vendored copies are the source of truth.Exporter
src/explain-json.ts—formatExplainJSON(statements)(one{version: 1, ast}document per statement) andexplainJSON(statement), exported fromsrc/index.ts. Pure formatting over AST data, reusingOP_TO_FUNCTIONand helpers extracted fromsrc/explain.ts. Covers the SELECT family (SELECT/UNION/INTERSECT/EXCEPT); other statement kinds throw.Grammar/AST fidelity fixes surfaced by the contract
Per repo convention, data missing from the AST became grammar changes rather than parsing inside the formatter. These were silently discarded by the parser before (and dropped by
format()):NULLS FIRST/LASTon ORDER BY (nullsFirst) and bareWITH FILL(withFill)RESPECT/IGNORE NULLSon functions (nullsAction)OVER wnamed-window references (windowName) and the parent window name inOVER (w …)— previously the entireOVER wclause was lostANY/ALL/ASOF/SEMI/ANTI),GLOBALlocality, and comma-join vsCROSS JOININTERSECT/EXCEPT DISTINCT(distincton the intersect node)isOperatormarker on operator-syntax desugar sites (arr[1],tup.2,BETWEEN,-x,LIKE,||,?:,IS NULL, …) so explicit calls likearrayElement(arr, 1)are distinguishable from operator syntaxformat.tsnow prints the new semantic fields;isOperatoris treated as surface-syntax metadata (stripped in round-trip/golden comparisons, likelocation). Self-goldens intests/clickhouse-referenceregenerated accordingly (~890 files).Test suite and tooling
tests/clickhouse-reference-ast-json.test.ts— mirrors the existing reference suites: parse each fixture, run the exporter, deep-compare structurally. All 41 cases pass; the documented skip/known-divergence list is empty.npm run diff:ast-jsonfollowing the existingdiff:*pattern, with key-order-insensitive diffs;diff-libgeneralized to support alternate corpus layouts.Known follow-ups
no-control-regexlint nit insrc/explain-json.ts(unescapeLabel).