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
### 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
- Pull request #9015: ClickHouse: parse projections without ORDER BY or GROUP BY (merged 2026-11-05).
-
dialect_clickhouse.py, the dialect file with
ProjectionBodySegment. - Pull request #8585, which introduced the grammar.
10. Limitations and observations
-
arnx did not rank this as a finding. The test failed on the
code before the change too, because the parent commit rejected every
ADD PROJECTION. arnx therefore listed it underalready failing before this change
, which does not get a second opinion. It was a gap in the new grammar. A person reading that section saw it. -
The one finding arnx confirmed in this review was wrong.
It asserted that
GROUP BYtogether withORDER BYshould parse. ClickHouse rejects that form (When aggregation is used in projection, ORDER BY cannot be specified
), so the grammar was right and the test was not. The second model agreed with the wrong test. -
The reviewer itself wrote that ClickHouse's behavior was
unconfirmed
. Settling it took reading ClickHouse's parser source, which a person did. - One review of one commit. It says nothing about how often arnx is right; the research note has the counts for the whole batch.
Last reviewed 2026-11-12 against arnx 0.1.11. The release documentation is canonical for your installed version.