[CALCITE-7440] Preserve correlated scope mapping in RelToSqlConverter#4828
[CALCITE-7440] Preserve correlated scope mapping in RelToSqlConverter#4828bvolpato wants to merge 6 commits intoapache:mainfrom
Conversation
6309f8d to
5447f29
Compare
4449f5a to
f11eed6
Compare
|
Thanks for the review! Updated this PR with both requested changes: Reduced the regression to the minimal reproducer on main (empty rules was a mistake):
Added a plain round-trip test without extra rules:
Both new/updated tests pass locally in this branch. |
6365d37 to
565cb6a
Compare
565cb6a to
a685206
Compare
|
Could we please consider @asolimando 's suggestion in Jira? Personally, I don't think this particular fix is entirely appropriate. Incidentally, regarding the structure of the test case: you might want to refer to other examples for guidance. Please avoid using |
|
@xiedeyantu I addressed the test-structure part of your note:
On the Jira alias suggestion: I considered it, but I kept this PR scoped to the failure mode reproduced here. The retained regression still fails on If you want, I can also split out the alias-cleanup direction as a separate follow-up. |
|
|
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 dev@calcite.apache.org list. Thank you for your contributions. |
287b8f2 to
541ce0c
Compare
|



Summary
RelToSqlConverter can lose correlation context during PostgreSQL round-trip conversion after the semi-join rewrite pipeline, causing
variable $cor1 is not found.Reproduction query
Reproducer rules
Error before this PR
Fix
Correlateleft inputs instead of exposing internal$cor*names.RexSubQueryrelations against the enclosing SQL context before visiting the subquery.Aggregateinputs during RelToSql conversion.Test
RelToSqlConverterTest.testPostgresqlRoundTripCorrelatedProjectWithSemiJoinRules.$cor*aliases before the round-trip.mainand passes with this patch.JAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew :core:test --tests org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.testPostgresqlRoundTripCorrelatedProjectWithSemiJoinRulesJAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew :core:test --tests org.apache.calcite.rel.rel2sql.RelToSqlConverterTest --tests org.apache.calcite.rel.rel2sql.RelToSqlConverterStructsTestJAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew :core:checkstyleMain :core:checkstyleTest :core:forbiddenApisMain :core:forbiddenApisTestJAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew :piglet:test --tests org.apache.calcite.test.PigRelOpTestJAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew :piglet:checkstyleTest :piglet:forbiddenApisTestDisclaimer
The changes were done with the assistance of Codex (gpt-5.3-codex) in response to an actual bug when using Calcite in production. The changes were manually verified prior to sending this to review.