Repository navigation
Fix query parameter substitution inside WINDOW clause definitions - #110506
Conversation
`ParserWindowList` stored the parsed window definition in the `definition` member of `ASTWindowListElement` but did not attach it to `children` (only `clone` did), so generic AST visitors never descended into the definitions of a named `WINDOW` clause. In particular, `ReplaceQueryParameterVisitor` did not substitute query parameters there: with a parameter set, the placeholder silently remained; with an unset `Identifier` parameter, an `ASTIdentifier` with an empty name part leaked into the query tree, and the `EXPLAIN SYNTAX` round trip via `IdentifierNode::toASTImpl` failed the `chassert(!part.empty())` in the `ASTIdentifier` constructor with the exception `Logical error: '!part.empty()'` in debug builds (found by AST fuzzer, STID 2508-2ef2, hitting dozens of unrelated PRs). The inline `OVER (...)` path already attached the definition to the children of `ASTFunction`; now the named `WINDOW` clause is consistent with it: parameters are substituted, and an unset parameter throws `UNKNOWN_QUERY_PARAMETER` instead of being silently kept. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100173&sha=b1e22dc973fff17a0d52660a132ef3f7a1d45498&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 Found on: #100173 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [3764123] Summary: ✅
AI ReviewSummaryThis PR fixes the missing AST-child link for named Final Verdict
|
…egression The AI review and the `clickhouse-gh` review thread asked to prove the view-DDL path end to end, not just direct `SELECT` / `EXPLAIN` substitution. The same missing child that hid query parameters under a named `WINDOW` from `ReplaceQueryParameterVisitor` also hid them from `ASTSelectQuery::hasQueryParameters`, which `ASTCreateQuery::isParameterizedView` relies on to classify a view as parameterized. Add a case that creates a view whose only query parameter lives inside a named `WINDOW` frame definition, checks it is classified as parameterized via `system.tables.parameterized_view_parameters`, and calls it with an argument to confirm the parameter is substituted at call time. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 2/3 (66.67%) · Uncovered code |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Very good fix!
|
Hi — this looks like a backport candidate for |
ORDER BY x WITH FILL INTERPOLATE (value AS {p:Int64}) failed with
UNKNOWN_QUERY_PARAMETER even when the parameter was supplied, while the
same parameter nested in a larger expression, such as value + {p:Int64},
worked.
ASTInterpolateElement stores its expression twice: in the member expr and
in children[0]. The parser, clone() and readJSON() all establish that
duplication. ReplaceQueryParameterVisitor does not mutate a parameter node
in place, it reassigns the ASTPtr slot it was handed, so visitChildren
afterwards asks the parent to retarget any duplicate member through
IAST::updatePointerToChild, which dispatches to the virtual
forEachPointerToChild. The base implementation of that hook is empty and
ASTInterpolateElement never overrode it, so the retarget did nothing:
children[0] received the substituted literal while expr kept pointing at
the released ASTQueryParameter. Every consumer of the clause reads ->expr,
which is why the query failed under both the old and the new analyzer.
The compound form was unaffected because expr then points at the plus
function, whose identity survives while its children are replaced in
place, and {p:Identifier} was unaffected because visitIdentifier mutates
that node in place.
Add the missing forEachPointerToChild override so the member follows the
child, matching the other AST classes that implement this hook. Because
the divergence is upstream of both analyzers, the single override fixes
both. This is a different mechanism from the WINDOW clause fix in ClickHouse#110506,
where the parser had never registered the child at all.
Closes ClickHouse#118458.
Co-Authored-By: Claude Opus 5 <[email protected]>
…e-query-parameters Fix query parameter substitution inside `WINDOW` clause definitions
Related: #100173
ParserWindowListstored the parsed window definition in thedefinitionmember ofASTWindowListElementbut did not attach it tochildren(onlyclonedid), so generic AST visitors never descended into the definitions of a namedWINDOWclause. In particular,ReplaceQueryParameterVisitordid not substitute query parameters there:SELECT count() OVER w WINDOW w AS (PARTITION BY {p:String})did not see the value);Identifierparameter, anASTIdentifierwith an empty name part leaked into the query tree, and theEXPLAIN SYNTAXround trip viaIdentifierNode::toASTImplfailed thechassert(!part.empty())in theASTIdentifierconstructor with the exceptionLogical error: '!part.empty()'in debug builds.The inline
OVER (...)path already attached the definition to the children ofASTFunction, so it was not affected; now the namedWINDOWclause is consistent with it: parameters are substituted, and an unset parameter throwsUNKNOWN_QUERY_PARAMETERinstead of being silently kept.The exception was found by the AST fuzzer (STID
2508-2ef2) and currently hits dozens of unrelated PRs (about 25 in the last 30 days); I did not find an existing tracking issue for it. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100173&sha=b1e22dc973fff17a0d52660a132ef3f7a1d45498&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix substitution of query parameters inside the definitions of a named
WINDOWclause. Previously, parameters there were silently kept unsubstituted, and an unsetIdentifierparameter could lead to the exceptionLogical error: '!part.empty()'duringEXPLAIN SYNTAX.Documentation entry for user-facing changes
Version info
26.7.1.1157(included in26.7and later)