Repository navigation
Conversation
…a body
SELECT * APPLY (x -> COLUMNS('a')) APPLY toString FROM (SELECT 1 AS a)
aborted the server in debug builds with the Inconsistent AST formatting
logical error, on both analyzers, from plain SQL with no settings. Found
by AST fuzzer (amd_debug), STID 1941-1bfa.
ASTColumnsApplyTransformer::formatImpl printed the lambda bare, opening
'(' only when column_name_prefix was set, so the parentheses the user
wrote were dropped:
in : SELECT * APPLY (x -> COLUMNS('a')) APPLY toString FROM t
out: SELECT * APPLY x -> COLUMNS('a') APPLY toString FROM t
On re-parse ParserColumnsTransformers sees no '(', leaves
with_open_round_bracket false and hands the tail to ParserExpression.
Because the lambda body is itself a matcher, the matcher grammar absorbs
the following APPLY toString into the lambda body rather than leaving it
as the next sibling transformer. Two ColumnsApplyTransformer children
collapse into one, the tree hash differs, and the round-trip check in
executeQuery aborts. The formatted text is idempotent, so only the AST
comparison catches this.
Print those parentheses unconditionally. They are the transformer
grammar's own delimiter, which is why the sibling column_name_prefix
branch has always emitted them and why that spelling never aborted.
A type-narrowed variant that parenthesizes only matcher-valued bodies
was rejected: it would have to enumerate every current and future
matcher node, and unconditional parentheses always re-parse.
Changing the parser to stop before a following transformer keyword was
also rejected, since it would alter the accepted language and
reinterpret already-persisted view definitions.
Formatted output changes only for APPLY <lambda>. The function-name
forms (APPLY toString, APPLY sum, APPLY quantile(0.5)) and both
column_name_prefix forms stay byte-identical, and appendColumnName is
untouched so result column names do not shift.
Validated on two debug builds: without the change the reproducer gives
rc=134 and the new test fails on both analyzers; with it the query runs
and the test passes. A 444-query sweep over matcher body kinds,
following-transformer kinds and prefix variants goes from 192 round-trip
aborts to 0, with no output or error-code change for any query that
already worked. Four existing reference files shift by one line each,
all of them formatter output of an APPLY lambda.
Remaining known gap, out of scope here: with the legacy analyzer,
APPLY (x -> <matcher>, 'prefix') still fails on Can't set alias, raised
by applyColumnsTransformer calling setAlias on a matcher node. That is a
separate pre-existing defect, unchanged by this commit and reproducible
on pristine master.
The previous commit made ASTColumnsApplyTransformer::formatImpl emit the lambda's parentheses but forwarded the format frame unchanged, so ASTFunction added its own pair on top: in : SELECT id, t.* APPLY x -> toString(x) FROM t out: SELECT id, t.* APPLY ((x -> toString(x))) FROM t ASTFunction's lambda branch brackets a lambda when need_parens is set or when list_element_index > 0, and nothing between ASTExpressionList and the transformer clears either flag. On master formatImpl emitted no bracket of its own, so that pair was the only one and the output was correct; with the new bracket it became redundant. Reset both flags for the lambda's frame, mirroring what decideParensEmission does in IAST.cpp when it takes over paren emission from a nested node. current_function is deliberately left alone: ASTFunction uses it to decide whether a nested IN needs isolating parentheses inside an argument list, which the transformer's brackets do not provide. This also drops one redundant pair from APPLY (<lambda>, 'prefix') at a select-list position > 0, which master already printed as APPLY ((x -> f(x)), 'prefix') from the same ASTFunction branch. It corrects the previous commit's claim that both column_name_prefix forms stay byte-identical: the index-0 form does, the later-position form now loses the redundant pair. Both re-parse to the same AST before and after, and result column names are unchanged in either position. 04846 gains a select-list-index > 0 carrier and an arrayMap-nested carrier, and its round-trip assertions now compare the parsed AST via parseQueryToJSON instead of comparing formatted text to itself. Text idempotence held before the fix as well, so those assertions could not have detected the original defect; six of the nine AST assertions return 0 on the pre-fix binary. The internal check the test mirrors likewise compares the tree hash before it reaches any string comparison.
Internal second-model review (2 rounds, 7 findings adjudicated)This PR went through an independent cold review plus a second-model gate over two rounds before
Also verified independently while reviewing, none of it a finding: the reference-churn set is |
Pre-PR validation gate (click to expand)
|
|
cc @evillique @george-larionov, could you review this? The APPLY transformer's formatter dropped the parentheses around a lambda, so with a matcher-valued body the following transformer was absorbed into the lambda on re-parse and one ColumnsApplyTransformer child was lost; the parentheses are now always printed, and ASTFunction's own pair for a lambda at a list position is suppressed so the output carries exactly one. |
|
Workflow [PR], commit [8f1849b] Summary: ❌
AI ReviewSummaryThis PR fixes Final Verdict✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 7a6387fEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Two rows are easy to misattribute, so the evidence is spelled out. The AST fuzzer rows are NOT caused by this PR, even though this PR edits The hung check is one specific trunk defect, not the umbrella. I parsed each Session id: cron:our-pr-ci-monitor:20260811-033000 |
|
Fixing PR for the hung |
CI finish ledger — 858f642Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Notes for readers:
Session id: cron:our-pr-ci-monitor:20260818-000000 |
CI finish ledger - 8f1849bEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
The two Coverage: 177 leaves, 157 OK, 18 skipped each with a genuine reason, 0 dropped, both aggregators Session id: cron:our-pr-ci-monitor:20260818-210000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the formatting of an
APPLYcolumn transformer whose lambda body is a matcher and which is followed by another transformer, as inSELECT * APPLY (x -> COLUMNS('a')) APPLY toString. The parentheses around the lambda were dropped, soformatQueryreturned text that parses back as a different query (the following transformer was absorbed into the lambda body), and in debug builds the query hit theInconsistent AST formattingLOGICAL_ERROR. Those parentheses are now always printed.Description
SELECT * APPLY (x -> COLUMNS('a')) APPLY toString FROM (SELECT 1 AS a)aborts the server indebug builds, and in a release build
formatQueryon it returns text that parses back as adifferent query. Pre-existing on master, both analyzers, plain SQL with no settings. Found by
AST fuzzer (amd_debug):CI report,
STID 1941-1bfa. Related: #100576.
Root cause:
ASTColumnsApplyTransformer::formatImplprinted the lambda bare, opening(onlywhen
column_name_prefixwas set, so the user's parentheses were dropped:On re-parse
ParserColumnsTransformerssees no(, so it hands the tail toParserExpression,and because the lambda body is itself a matcher the matcher grammar absorbs the following
APPLY toStringinto it. TwoColumnsApplyTransformerchildren collapse into one. The formattedtext is idempotent, so only the AST differs.
The fix prints those parentheses unconditionally: they are the transformer grammar's own
delimiter, which is why the sibling
column_name_prefixbranch has always emitted them and thatspelling never aborted. Since they now delimit the lambda,
ASTFunction's own parenthesis for alambda at a list position is suppressed, so the output carries exactly one pair. The
function-name forms are byte-identical, and
appendColumnNameis untouched so result columnnames do not shift.
Validated on two debug builds: without the change the reproducer gives
rc=134and the new testfails; with it the query runs and the test passes. Across a 444-query sweep on both analyzers,
192 round-trip aborts drop to 0 and no query that already worked changes its result or error code.
Not fixed here: with the legacy analyzer,
APPLY (x -> <matcher>, 'prefix')still fails withCan't set aliasfromapplyColumnsTransformer, a separate pre-existing defect.Validation detail
rc=134,Inconsistent AST formattingrc=0, returns104846(analyzer 1 / 0)APPLY toString/APPLY sum/APPLY quantile(0.5)/APPLY (toString, 'p_')04846, 50 randomized runs; and 50 more withenable_analyzer=0inconsistent_ast(8),ast_json(49),columns_transformer,columns_matcher,analyzer_projection_namesFour
.referencefiles shift by one line each, all of them formatter output of anAPPLYlambda:
01470_columns_transformers2,04320_ast_json_review_hardening,04339_ast_json_review_followup_hardening,04344_ast_json_select_child_typing.Workflow [PR]
Sync PR [sync-upstream/pr/114205]