Repository navigation
Format the composition operator f | g as an operator inside CODEC and other function-call-form contexts - #125567
Conversation
…ll-form contexts In `CODEC`, `STATISTICS`, backup engine arguments, the `ELSE` argument of `viewIfPermitted` and `EXPLAIN SYNTAX`, `ASTFunction` writes operators as function calls. The `__compose` branch was inside the block that runs only when operators are allowed, so there `f | g` was written as `__compose(f, g)`. That text parses back as an ordinary call, and the tree hash of `__compose` includes `isOperator()` on purpose (c445e7b), so debug builds failed the round-trip check in `executeQuery` with "Inconsistent AST formatting", and `EXPLAIN SYNTAX` of a non-SELECT query printed text that does not run. Found by the AST fuzzer in Stress test (amd_debug), which put `arrayMap(plus(_, 1048577) | multiply(-2147483648), [2])` into a column codec. Move the branch in front of the `allow_operators` check with the same conditions and body. Output where operators are allowed does not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (2 nits, no blocker or major).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261013-071500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261013-063600 |
|
Workflow [PR], commit [f095628] Summary: ✅
AI ReviewSummaryPreserves the Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - a9fa845Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261013-113003 |
|
Fixing PR for the targeted-job test-selection |
…r-in-call-form # Conflicts: # src/Parsers/ASTFunction.cpp
|
@groeneai @alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
… an operand of `|` In function-call form (`CODEC`, `STATISTICS`, backup engine arguments, `viewIfPermitted ... ELSE`, `EXPLAIN SYNTAX`) ClickHouse#125567 prints `f | g` as an operator and groups each operand by formatting it with `need_parens`. Every call-form function is printed as an atomic `name(args)`, except a one-argument `not`, which is written bare (`is_plain_not_call`) because a standalone `not(x)` parses back to the same AST. But `not(` is operator syntax for the parser (prefix `NOT`, priority 5, below `|` at priority 8), and unlike the operator-form `NOT` that writer ignored `need_parens`; the user's own `(NOT a)` parentheses are dropped too, since call form suppresses the `parenthesized` parentheses of every function. So `(NOT a) | b` was printed as `not(a) | b`, which parses back as `not(__compose(a, b))`: debug and sanitizer builds hit the `Inconsistent AST formatting` LOGICAL_ERROR, and `EXPLAIN SYNTAX` output for such a query failed with `Code: 43` when run. The bare `not(x)` writer now honours `need_parens` exactly like the operator form, so it prints `(not(a)) | b`, which parses back to the same AST (the tree hash ignores `parenthesized`) and formats to itself. `__compose` stays unaware of its operands' syntax. The only other call-form caller that sets `need_parens` is a window frame offset, which now prints `(not(0)) PRECEDING` in `EXPLAIN SYNTAX`, matching the operator form; both texts run identically. Declaration formatters (DEFAULT, ORDER BY, TTL, ...) set it only for an aliased expression, and the alias formatter consumes it, so they are unchanged. Closes ClickHouse#130934 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #116029
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed formatting of the function composition operator
f | ginsideCODEC,STATISTICS, backup engine arguments and theEXPLAIN SYNTAXoutput of non-SELECTqueries: it was written as a call to__compose, which could not be run back.Description
On 26.10.2.103,
EXPLAIN SYNTAX CREATE TABLE t (x Array(UInt64) DEFAULT arrayMap(plus(_, 1) | multiply(_, 2), [1])) ENGINE = MemoryprintsarrayMap(__compose(plus(_, 1), multiply(_, 2)), [1]), which fails withCode: 36when run.CI:
Stress test (amd_debug)on #117704 aborted withLogical error: 'Inconsistent AST formatting: the original AST: ... differs from the result of parsing back formatted AST'(report). The fuzzer putarrayMap(plus(_, 1048577) | multiply(-2147483648), [2])inside a column codec. The shortest form, on a debug build:Root cause. Inside
CODEC,STATISTICS, backup engine arguments,viewIfPermitted ... ELSEandEXPLAIN SYNTAX,ASTFunctionwrites operators as calls. The__composebranch sat inside that operators-allowed block, sof | gcame out as__compose(f, g). That text re-parses as an ordinary call, and the tree hash tells the two apart on purpose (c445e7b), so the round-trip check fails.Change. Write
f | gas the operator in every context. The__composebranch moves in front of theallow_operatorscheck, with the same conditions and body. Contexts that allow operators produce exactly the same output, and an ordinary__compose(a, b)call is still written as a call.|came in #116029 and is released in 26.10.Validation. A new test covers
EXPLAIN SYNTAXof a codec and a default, aSTATISTICSclause, and nested composition inALTER ... CODEC. On master its first line aborts a debug server with the CI message; with the fix it passes, 50/50 with random settings. The existing function composition tests pass.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125567]
Version info
26.11.1.1985-master(included in26.11and later)