julianhyde commented on code in PR #4061:
URL: https://github.com/apache/calcite/pull/4061#discussion_r1855141945
##########
core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml:
##########
@@ -6513,12 +6552,11 @@ LIMIT 5]]>
LogicalSort(sort0=[$2], dir0=[ASC], fetch=[5])
LogicalAggregate(group=[{0, 1, 2, 3}])
LogicalProject(EMPNO=[$0], ENAME=[$1], DEPTNO=[$2], RANK_VAL=[$3])
- LogicalFilter(condition=[$5])
- LogicalProject(EMPNO=[$0], ENAME=[$1], DEPTNO=[$2], RANK_VAL=[$3],
EXPR$0=[$4], QualifyExpression=[=($3, $4)])
+ LogicalFilter(condition=[$4])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], DEPTNO=[$7], RANK_VAL=[RANK()
OVER (PARTITION BY $1 ORDER BY $7 DESC)], QualifyExpression=[=(RANK() OVER
(PARTITION BY $1 ORDER BY $7 DESC), $9)])
Review Comment:
I made note of this regression, and I'd rather it had not happened, but I
don't view it as very serious. `Project` (unlike `Calc`) is not able to
represent common subexpressions, so the appearance of duplicate expressions in
`Project` does not mean that they are going to be executed separately.
A reasonable planner configuration will do subexpression elimination.
Sql-to-rel shouldn't try too hard to do that.
##########
core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml:
##########
@@ -6568,11 +6606,10 @@ QUALIFY rank_val = (SELECT COUNT(*) FROM emp)]]>
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], DEPTNO=[$2], RANK_VAL=[$3])
- LogicalFilter(condition=[$5])
- LogicalProject(EMPNO=[$0], ENAME=[$1], DEPTNO=[$2], RANK_VAL=[$3],
EXPR$0=[$4], QualifyExpression=[=($3, $4)])
+ LogicalFilter(condition=[$4])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], DEPTNO=[$7], RANK_VAL=[RANK() OVER
(PARTITION BY $1 ORDER BY $7 DESC)], QualifyExpression=[=(RANK() OVER
(PARTITION BY $1 ORDER BY $7 DESC), $9)])
Review Comment:
I don't know. The cause of this bug seems simple - the qualify expression
needs to be translated relative to the inputs to the SELECT clause, not
relative to the outputs - and when I did that, the query seems to work.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]