[
https://issues.apache.org/jira/browse/CALCITE-4592?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Amandeep Sharma updated CALCITE-4592:
-------------------------------------
Description:
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
{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}
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.
was:
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
{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}
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 tables 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.
> 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
> Priority: Major
> Labels: pull-request-available
> Time Spent: 20m
> 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
> {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}
>
> 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.3.4#803005)