calcite icon indicating copy to clipboard operation
calcite copied to clipboard

[CALCITE-4592] Populate correlation context for Join in RelToSqlConve…

Open amandeep-sharma opened this issue 4 years ago • 2 comments

…rter

Correlation context is populated in RelToSqlConverter 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 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

Version 1.26 stack-trace 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)

amandeep-sharma avatar Apr 27 '21 05:04 amandeep-sharma

Good day! Found out that this query produces same exception (java.lang.NullPointerException: variable $cor0 is not found) query: SELECT t.id, (select b.id FROM tbl2 AS b WHERE b.id = t.id) FROM tbl1 as t it parsed/validated successfully, but can't be converted back to sql. Can it be fixed in this pr or it is another issue?

FDoKE avatar Jun 07 '21 07:06 FDoKE

Good day! Found out that this query produces same exception (java.lang.NullPointerException: variable $cor0 is not found) query: SELECT t.id, (select b.id FROM tbl2 AS b WHERE b.id = t.id) FROM tbl1 as t it parsed/validated successfully, but can't be converted back to sql. Can it be fixed in this pr or it is another issue?

@FDoKE It seems that your use case is correlating the sub-query with Project. It is different from the PR use-case which is correlating the sub-query with Join. Correlating the sub-query is supported only with Correlate and LogicalFilter; Join is being added in this PR. Support for correlatingProject is doable, but I would prefer to make those changes in a separate PR.

amandeep-sharma avatar Jun 08 '21 06:06 amandeep-sharma