To find the next explain test to work on (fewest pending statements first), run:
go run ./cmd/next-testThis finds tests with explain_todo entries in their metadata.
Always run parser tests with a 30 second timeout:
go test ./parser/... -timeout 30sThe tests are fast but some test files have many statements. If a test is timing out, it may indicate a bug (likely an infinite loop in the parser).
IMPORTANT: After implementing parser/explain changes, ALWAYS run check-explain to update metadata files:
go test ./parser/... -check-explain -v 2>&1 | grep "EXPLAIN PASSES NOW"This command:
- Runs all explain tests including those in
explain_todo - Automatically updates
metadata.jsonfiles to remove passing statements fromexplain_todo - Reports which tests now pass
You must run this after every change to parser or explain code, then commit the updated metadata.json files along with your code changes.
explain*.txt files are generated by the ClickHouse version pinned in cmd/regenerate-explain/main.go (currently 26.8 LTS). The tool downloads that release, starts a local server and queries it over HTTP:
go run ./cmd/regenerate-explain # all tests (under a minute)
go run ./cmd/regenerate-explain -test NAME # one testAfter moving to a new ClickHouse version or importing new tests, record the statements that don't pass yet:
go test ./parser/... -mark-todoThis adds failing statements to explain_todo instead of failing, so the suite stays green while they are worked down.
Each test in parser/testdata/ contains:
metadata.json-{}for enabled testsquery.sql- ClickHouse SQL to parseexplain.txt- Expected EXPLAIN AST output (matches ClickHouse's format)explain_N.txt- Expected EXPLAIN AST output for Nth statement (N >= 2)
explain_todo: {"stmt2": true}- Skip specific statement subtestsskip: true- Skip test entirely (e.g., causes infinite loop)explain: false- Skip test (e.g., ClickHouse couldn't parse it)parse_error: true- Query is intentionally invalid SQL
NEVER modify explain.txt files - These are golden files containing the expected output from ClickHouse. If tests fail due to output mismatches, fix the Go code to match the expected output, not the other way around.