calcite icon indicating copy to clipboard operation
calcite copied to clipboard

[CALCITE-4693] Query with Lateral Join should converted to Left Join …

Open NobiGo opened this issue 5 months ago • 5 comments

…When sub-query is aggregate qurey

NobiGo avatar Jul 22 '25 03:07 NobiGo

I believe this is not the root cause of the incorrect query results. It's related to https://github.com/apache/calcite/pull/4375.

The issue occurs in the Decorrelator. PR-4375 appears to have missed some cases where parentPropagatesNullValues should be set to false when Correlate's joinType is not Left.

I'm confident the following modification can fix all tests in this PR.

diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
index b5500c871..e150079c7 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
@@ -1629,7 +1629,8 @@ private static boolean isWidening(RelDataType type, RelDataType type1) {
     }
 
     frameStack.push(Pair.of(rel.getCorrelationId(), leftFrame));
-    final Frame rightFrame = getInvoke(oldRight, true, rel, parentPropagatesNullValues);
+    final Frame rightFrame = getInvoke(oldRight, true, rel,
+        parentPropagatesNullValues && rel.getJoinType() == JoinRelType.LEFT);
     frameStack.pop();

suibianwanwank avatar Jul 24 '25 03:07 suibianwanwank

I believe this is not the root cause of the incorrect query results. It's related to #4375.

The issue occurs in the Decorrelator. PR-4375 appears to have missed some cases where parentPropagatesNullValues should be set to false when Correlate's joinType is not Left.

I'm confident the following modification can fix all tests in this PR.

diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
index b5500c871..e150079c7 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
@@ -1629,7 +1629,8 @@ private static boolean isWidening(RelDataType type, RelDataType type1) {
     }
 
     frameStack.push(Pair.of(rel.getCorrelationId(), leftFrame));
-    final Frame rightFrame = getInvoke(oldRight, true, rel, parentPropagatesNullValues);
+    final Frame rightFrame = getInvoke(oldRight, true, rel,
+        parentPropagatesNullValues && rel.getJoinType() == JoinRelType.LEFT);
     frameStack.pop();

I will recheck this.

NobiGo avatar Jul 25 '25 01:07 NobiGo

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Aug 25 '25 03:08 github-actions[bot]

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Oct 25 '25 03:10 github-actions[bot]