Skip to content

[CALCITE-7442] fix correlated variable's index inside subquery#4840

Open
yashlimbad wants to merge 1 commit intoapache:mainfrom
yashlimbad:correlate_subquery_fix
Open

[CALCITE-7442] fix correlated variable's index inside subquery#4840
yashlimbad wants to merge 1 commit intoapache:mainfrom
yashlimbad:correlate_subquery_fix

Conversation

@yashlimbad
Copy link

@yashlimbad yashlimbad commented Mar 18, 2026

Jira Link

CALCITE-7442

Changes

Adjust offset of correlated variable inside subquery when pushing filter via FilterJoinRule.java

@yashlimbad yashlimbad force-pushed the correlate_subquery_fix branch 4 times, most recently from 53f3132 to fb20a82 Compare March 18, 2026 16:08
@xiedeyantu
Copy link
Member

There is an error in the CI that needs to be resolved.

@yashlimbad yashlimbad force-pushed the correlate_subquery_fix branch from fb20a82 to e6ebfcc Compare March 19, 2026 02:58
@yashlimbad
Copy link
Author

Updated the Code.

@sonarqubecloud
Copy link

@xiedeyantu xiedeyantu requested a review from Copilot March 19, 2026 07:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a decorrelation/planning correctness issue (CALCITE-7442) where a correlated variable’s field index inside a subquery can become incorrect after FilterJoinRule pushes filters.

Changes:

  • Add a regression test that exercises FILTER_INTO_JOIN + FILTER_SUB_QUERY_TO_CORRELATE and then decorrelates, asserting expected plans.
  • Extend FilterJoinRule to propagate correlation-variable sets when creating pushed-down filters (and when keeping an above-join filter).
  • Enhance RelOptUtil.classifyFilters shifting logic so correlated field accesses inside RexSubQuery.rel can be adjusted during filter pushdown.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
core/src/test/java/org/apache/calcite/sql2rel/RelDecorrelatorTest.java Adds a regression test covering correlated variable index behavior through filter pushdown + decorrelation.
core/src/main/java/org/apache/calcite/rel/rules/FilterJoinRule.java Tracks correlation variables when constructing new Filters after pushdown.
core/src/main/java/org/apache/calcite/plan/RelOptUtil.java Extends filter-shifting to also adjust correlated field accesses inside subqueries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@xiedeyantu
Copy link
Member

I'm not sure if these comments will be helpful, as I'm not very familiar with this specific area. If someone more knowledgeable doesn't review this PR within the next few days, I'll give it a try myself.

@yashlimbad
Copy link
Author

some comments were looking helpful so I updated code now will check by running build if it goes through and push accordingly! 😄 it's fine if someone reviews code in few days, but I feel @julianhyde would be the best to review this because I see only his commit on RelOptUtil which I updated which is called from FilterJoinRule

@yashlimbad yashlimbad force-pushed the correlate_subquery_fix branch 2 times, most recently from 45e98e9 to 2c9af44 Compare March 19, 2026 09:11
@yashlimbad yashlimbad force-pushed the correlate_subquery_fix branch from 2c9af44 to 815c57d Compare March 19, 2026 11:26
@yashlimbad
Copy link
Author

yashlimbad commented Mar 19, 2026

sometimes the tests passes sometimes fails randomly with below error in CI

Execution failed for task ':arrow:test'.
> Could not resolve all dependencies for configuration ':arrow:jacocoAgent'.
   > Could not load module metadata from /home/jenkins/.gradle/caches/modules-2/metadata-2.106/descriptors/org.jacoco/org.jacoco.agent/0.8.11/26c913274550a0b2221f47a0fe2d2358/descriptor.bin

even tho gradlew build is passed
it will be good if this CI run is consistent

@xiedeyantu xiedeyantu added the request review request a review from committers/contributors label Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request review request a review from committers/contributors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants