[CALCITE-7440] Preserve correlated scope mapping in RelToSqlConverter#4828
[CALCITE-7440] Preserve correlated scope mapping in RelToSqlConverter#4828bvolpato wants to merge 4 commits intoapache:mainfrom
Conversation
6309f8d to
5447f29
Compare
4449f5a to
f11eed6
Compare
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
Show resolved
Hide resolved
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
Outdated
Show resolved
Hide resolved
|
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. |
|



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
Aggregateinputs during RelToSql conversion.Test
RelToSqlConverterTest.testPostgresqlRoundTripCorrelatedProjectWithSemiJoinRulesmainand passes with this patchJAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew :core:test --tests org.apache.calcite.rel.rel2sql.RelToSqlConverterTest.testPostgresqlRoundTripCorrelatedProjectWithSemiJoinRulesDisclaimer
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.