You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Chunwei Lei (JIRA)" <ji...@apache.org> on 2019/04/08 15:55:00 UTC

[jira] [Comment Edited] (CALCITE-1338) JoinProjectTransposeRule makes wrong transformation when the right child of left outer join has a RexLiteral project expression.

    [ https://issues.apache.org/jira/browse/CALCITE-1338?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16812531#comment-16812531 ] 

Chunwei Lei edited comment on CALCITE-1338 at 4/8/19 3:54 PM:
--------------------------------------------------------------

To resolve this, I would like to proposal:
 * add a new method named isStrict in SqlOperator to indicate whether the operator is strict or not
 * add a check in JoinProjectTransposeRule to assure not transform when the project has literal or non-strict  call

The code looks like as follows:
{code:java}
if (includeOuter) {
  Project project = null;
  if (rightProj != null
     && joinType.generatesNullsOnRight()) {
    project = rightProj;
  } else if (leftProj != null && joinType.generatesNullsOnLeft()) {
    project = leftProj;
  }
 
  if (project != null) {
  for (RexNode node: project.getProjects()) {
    if (node instanceof RexLiteral) {
      return;
    } else if (node instanceof RexCall) {
      RexCall rexCall = (RexCall) node;
      if (!rexCall.getOperator().isStrict()) {
        return;
      }
    }
  }
 }
}
{code}
Can someone check whether it is a right way? Appreciate it.

 


was (Author: chunwei lei):
To resolve this, I would like to proposal:
 * add a new method named isStrict in SqlOperator to indicate whether the operator is strict or not
 * add a check in JoinProjectTransposeRule to assure not transform when the project has literal or non-strict  call

The code looks like as follows:
{code:java}
if (includeOuter) {
  Project project = null;
  if (rightProj != null
     && joinType.generatesNullsOnRight()) {
    project = rightProj;
  } else if (leftProj != null && joinType.generatesNullsOnLeft()) {
    project = leftProj;
  }
 
  if (project != null) {
  for (RexNode node: project.getProjects()) {
    if (node instanceof RexLiteral) {
      return;
    } else if (node instanceof RexCall) {
      RexCall rexCall = (RexCall) node;
      if (!rexCall.getOperator().isStrict()) {
        return;
      }
    }
  }
 }
}

{code}

> JoinProjectTransposeRule makes wrong transformation when the right child of left outer join has a RexLiteral project expression.
> --------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-1338
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1338
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Yi Xinglu
>            Assignee: Chunwei Lei
>            Priority: Major
>
> h3. SQL: 
> {code:borderStyle=solid}
> SELECT * 
> FROM dept a 
> LEFT JOIN (
>   SELECT b.name, 1 FROM dept b
> ) AS b 
> ON a.name=b.name
> {code}
> h3. Selected rule set:
> {code:borderStyle=solid}
>   SubQueryRemoveRule.JOIN
>   JoinProjectTransposeRule.RIGHT_PROJECT_INCLUDE_OUTER
> {code}
> h3. Optimized logical plan:
> {code:borderStyle=solid}
> LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2], EXPR$1=[$3])
>   LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2], EXPR$1=[CAST($3):INTEGER])
>     LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$3], EXPR$1=[1])
>       LogicalJoin(condition=[=($3, $1)], joinType=[left])
>         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
>         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
> {code}
> h3. The right logical plan should be
> {code:borderStyle=solid}
> LogicalProject(DEPTNO=[$0], NAME=[$1], NAME0=[$2], EXPR$1=[$3])
>   LogicalJoin(condition=[=($2, $1)], joinType=[left])
>     LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
>     LogicalProject(NAME=[$1], EXPR$1=[1])
>       LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
> {code}
> h3. Summary
> The RexLiteral project expression will make logical plan get different results when it's right child or parent node of left outer join.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)