Repository navigation
Fix WITH function-expression alias in CREATE VIEW with IN clause - #100042
Merged
alexey-milovidov merged 1 commit intoMar 23, 2026
Merged
alexey-milovidov merged 1 commit into
alexey-milovidov merged 1 commit into
Conversation
`ApplyWithSubqueryVisitor` only collected `ASTWithElement` (subqueries) and `ASTLiteral` into its data maps, but missed `ASTFunction` and other expression types. Without replacement, `AddDefaultDatabaseVisitor` then qualified the identifier as a table name, causing `UNKNOWN_IDENTIFIER`. Replace the `ASTLiteral`-only check with a generic `tryGetAlias` check, so any aliased expression (including `ASTFunction`) is properly collected. Fixes ClickHouse#99308
alexey-milovidov
approved these changes
Mar 21, 2026
Contributor
|
Workflow [PR], commit [8ce6726] Summary: ✅ AI ReviewSummaryThis PR fixes ClickHouse Rules
Final Verdict
|
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 100.00% (15/15, 0 noise lines excluded) |
alexey-milovidov
pushed a commit
that referenced
this pull request
Oct 4, 2026
…ryVisitor `ApplyWithSubqueryVisitor` registered as a substitutable literal only the alias of a direct `WITH` child, so in `WITH tuple([7] AS nested) AS wrapper` it registered `wrapper` but not `nested`. A nested `SELECT` using `7 IN nested` then kept the identifier, and the full `AddDefaultDatabaseVisitor` traversal, which treats every name left in place as a table, qualified it as `<db>.nested`. A view, a materialized view, `MODIFY QUERY` and `ALTER TABLE ... UPDATE` with that shape read a same-named table instead of the alias, or failed with `UNKNOWN_IDENTIFIER` (reproduced on 26.8.2.7 and 26.3.33.24). The narrow pass that repairs a definition after SQL UDF expansion already takes the aliases at any depth of a `WITH` expression, not inside a lambda or a subquery, like the analyzer. A `Replicated` database writes that repaired text into the DDL log and every replica processes it again through the full pipeline, which re-qualified the alias. This made `05237_with_expression_alias_scope_descendant` fail on every run under `--replicated-database`. Register every such alias right after the expression is visited, as the direct child's alias was before, so it is inlined (`7 IN ([7] AS nested)`) the way a top-level alias has been since #100042. The rule now lives in one helper, `ApplyWithSubqueryVisitor::forEachWithExpressionAlias`, which the narrow pass also calls. The test gets back the mutation arms removed in the #114908 rework, each on its own row, and a hand-written view arm. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ApplyWithSubqueryVisitoronly collectedASTWithElement(subqueries) andASTLiteralinto its data maps, but missedASTFunctionand other expression types. Without replacement,AddDefaultDatabaseVisitorthen qualified the identifier as a table name (e.g.default.ev), causingUNKNOWN_IDENTIFIER.Replace the
ASTLiteral-only check with a generictryGetAliascheck, so any aliased expression (includingASTFunction) is properly collected.Fixes #99308
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
CREATE VIEWfailing withUNKNOWN_IDENTIFIERwhen using a WITH function-expression alias (e.g.tuple(...)) as the right-hand side ofIN.Documentation entry for user-facing changes
Version info
26.4.1.162