Case study / SQLFluff

Valid ClickHouse projections were unparsable.

A real gap, found by a test arnx had filed under the wrong heading.

SQLFluff is a SQL linter and formatter. A review of one of its commits produced a test showing that the new ClickHouse projection grammar rejected valid SQL. The fix was merged upstream on 2026-11-05 as sqlfluff/sqlfluff#9015. The same review also shows two things arnx got wrong.

1. Repository and reviewed commit

sqlfluff/sqlfluff, commit c81671b3d, which added ClickHouse projection support (upstream pull request #8585, for issue #8583): 7 files, 2,684 lines added. The commit was picked by a rule fixed before any run, as part of the experiment described in AI code review findings on unfamiliar repositories. arnx had no earlier contact with the repository.

2. Expected behavior

ClickHouse accepts a projection whose query has no ORDER BY and no GROUP BY. Its own parser, ParserProjectionSelectQuery.cpp, parses WHERE, GROUP BY and ORDER BY only when present. So these should parse:

ALTER TABLE t ADD PROJECTION p (SELECT sum(x));
ALTER TABLE t ADD PROJECTION p (SELECT x WHERE y = 1);

3. Actual behavior

sqlfluff parse --dialect clickhouse reported an unparsable section for both statements.

4. Suspected defect

Before any test ran, the second hunter (gpt-6.1-sol) suspected: Projection queries without GROUP BY or ORDER BY are incorrectly rejected. In ProjectionBodySegment the grammar listed ORDER BY or GROUP BY as a required OneOf.

5. Generated test

The reviewer wrote test_s2_projection_without_order_or_group in test/arnx_generated/test_ch_proj.py: parse a projection with a bare SELECT and assert that nothing is unparsable. A second test from a different suspicion checked the same gap with SELECT a, b.

6. Execution result

From review.md, quoted
### F1 · already failing before this change
- Test: `test/arnx_generated/test_ch_proj.py::test_s2_projection_without_order_or_group`
- Failure: `AssertionError: assert False`
- Reviewer: The projection grammar requires ORDER BY or GROUP BY. A bare SELECT in a
  projection fails to parse. The S5 test shows the same problem. Whether ClickHouse
  accepts a bare SELECT in a projection is unconfirmed.
- Before the change (pre-existing): fails the same way on the code before the change
  (3 runs): the change did not cause it

The review ran 27 tests in 3 minutes 51 seconds for $0.28. Reviewer: claude-sonnet-5-5. Second opinion: GLM-5.3-Flash through River. These numbers come from our local review record, not from a public page.

7. Correction

The fix marks that OneOf as optional: a small change in src/sqlfluff/dialects/dialect_clickhouse.py, plus parser fixtures for alter_table and create_table. Claude wrote the fix and fixtures. The owner of arnx reproduced the bug, ran the tests, reviewed the change and opened the pull request, with the AI disclosure SQLFluff's contributing guide asks for.

8. Verification result

From the pull request: the new fixtures fail without the fix, and with it all of test/dialects/ passes (7,858 passed). A maintainer approved it and it was merged the same day, commit 106b3902.

9. Upstream references

10. Limitations and observations

Last reviewed 2026-11-12 against arnx 0.1.11. The release documentation is canonical for your installed version.