[CALCITE-7502] RelToSqlConverter creates invalid sql when converting …#4918
Merged
mihaibudiu merged 1 commit intoapache:mainfrom May 5, 2026
Merged
Conversation
…nested window contains SqlCaseWhen
5f5326b to
cee63d5
Compare
|
mihaibudiu
approved these changes
May 5, 2026
Contributor
|
CI failed with a timeout, if it passes, I plan to merge. |
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.



…nested window contains SqlCaseWhen
Jira Link
CALCITE-7502
Changes Proposed
SqlImplementor.Result.containsOver() uses manual recursion to detect WINDOW nodes in a SQL tree, but only handles SqlSelect and SqlCall. Nodes such as SqlCase, SqlNodeList,
SqlLiteral, and others are silently skipped.
When a SqlCase expression contains a windowed aggregate (e.g.,
CASE WHEN SUM(x) OVER (...) > 1 THEN 1 ELSE 0 END)containsOver() returns false. This causes needNewSubQuery() to
incorrectly conclude that a new sub-query is not required, leading to incorrectly merged SELECT clauses with overlapping window functions.
SQL:
converted to LogicalPlan
and use RelToSqlConverter creates invalide sql, it contains a nested window function.
Fix:
Replace the manual recursion with a SqlBasicVisitor that properly traverses all SqlCall subtypes, including SqlCase.