silundong commented on code in PR #4997:
URL: https://github.com/apache/calcite/pull/4997#discussion_r3378630634


##########
core/src/test/resources/sql/sub-query.iq:
##########
@@ -8168,6 +8168,578 @@ SELECT deptno FROM dept WHERE 1000.00 >
 
 !ok
 
+# [CALCITE-7584] RelDecorrelator produces incorrect results for correlated 
LATERAL sub-queries with window functions
+# Correlated LATERAL sub-query with a window expression.
+# The equality predicate between the inner and outer query must remain applied
+# after decorrelation.
+SELECT e.ename, d.deptno, d.m
+FROM emp e
+JOIN LATERAL (
+  SELECT d.deptno,
+    MAX(d.deptno + e.empno) OVER (PARTITION BY e.deptno) AS m
+  FROM dept d
+  WHERE e.deptno = d.deptno
+) d ON TRUE
+ORDER BY e.empno;
+!if (use_old_decorr) {

Review Comment:
   It seems this is because the new decorrelator forgot to rewrite the ORDER BY 
clause in the window function. Thanks for catching this, I’ll report and fix it.



-- 
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]

Reply via email to