[
https://issues.apache.org/jira/browse/CALCITE-4592?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Yu Xu resolved CALCITE-4592.
----------------------------
Fix Version/s: 1.43.0
Resolution: Fixed
Fixed in
[https://github.com/apache/calcite/commit/83a36ba09be41ce447773feb231716b2b4e71198]
Thank you reported this Jira [~amsharma]
Thank you for the review [~mbudiu]
> RelToSqlConverter#visit(Join e) does not populate correlation context
> ---------------------------------------------------------------------
>
> Key: CALCITE-4592
> URL: https://issues.apache.org/jira/browse/CALCITE-4592
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.26.0
> Reporter: Amandeep Sharma
> Assignee: Yu Xu
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.43.0
>
> Time Spent: 1h
> Remaining Estimate: 0h
>
> Correlation context is populated for the followings:
> * Project
> * Filter
> * Calc
> * Correlate
> But it is not populated for _Join._ Because of it, using joiner's correlation
> id causes below exception
> Version 1.21 stack-trace
> {code:java}
> Caused by:
> java.lang.NullPointerException
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:506)
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:828)
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:668)
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:828)
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:668)
> at
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:213)
> ... 65 more
> {code}
> Version 1.26 stack-trace
> {code:java}
> java.lang.NullPointerException: variable $cor0 is not found
> at java.util.Objects.requireNonNull(Objects.java:290)
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$BaseContext.getAliasContext(SqlImplementor.java:1493)
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:709)
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:1132)
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.callToSql(SqlImplementor.java:851)
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:827)
> at
> org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:338)
> {code}
> Use case is to generate below query/ query with same semantic, having a
> scalar sub-query with correlated condition in the projection:
> {code:java}
> SELECT
> CUSTOMER.CUSTOMER_ID, --RexInputRef from join
> CUSTOMER.NAME, -- RexInputRef from join
> PAYMENT.PAYMENT_ID, -- RexInputRef from join
> (SELECT PAYMENT.AMOUNT FROM PAYMENT WHERE CUSTOMER.CUSTOMER_ID =
> PAYMENT.CUSTOMER_ID) AS AMOUNT --RexSubQuery
> FROM CUSTOMER LEFT JOIN PAYMENT ON CUSTOMER.CUSTOMER_ID =
> PAYMENT.CUSTOMER_ID; --$cor0
> {code}
> *Schema Tables*
> {code:java}
> CUSTOMER
> +- CUSTOMER_ID
> +- NAME
> PAYMENT
> +-PAYMENT_ID
> +-CUSTOMER_ID
> +-AMOUNT
> {code}
> For scalar sub-query, the input table is PAYMENT.
> Join's correlated field CUSTOMER_ID ($cor0.CUSTOMER_ID) needs to be binded in
> the scalar sub-query's condition: $cor0.CUSTOMER_ID = $1
> While materializing correlated field, it will be resolved to the CUSTOMER
> table's CUSTOMER_ID field.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)