DongShengHe created CALCITE-7502:
------------------------------------
Summary: SqlToRelConverter creates invalid plan when converting
nested window contains SqlCaseWhen
Key: CALCITE-7502
URL: https://issues.apache.org/jira/browse/CALCITE-7502
Project: Calcite
Issue Type: Bug
Reporter: DongShengHe
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.,
{code:java}
CASE WHEN SUM(x) OVER (...) > 1 THEN 1 ELSE 0 END) {code}
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.
Fix:
Replace the manual recursion with a SqlBasicVisitor that properly traverses
all SqlCall subtypes, including SqlCase.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)