You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Xurenhe (Jira)" <ji...@apache.org> on 2022/10/10 11:39:00 UTC

[jira] [Commented] (CALCITE-4982) NonNull field shouldn't be pushed down into leaf of outer-join in 'ProjectJoinTransposeRule'

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

Xurenhe commented on CALCITE-4982:
----------------------------------

Hi [~libenchao] 
As PR said, there are two solutions:
 # Avoid pushing down with the operand of coalesce's operator
 # Keep pushing down, and fix `{{{}org.apache.calcite.plan.Strong#policy(org.apache.calcite.rex.RexNode){}}}`

I went through the history, and found CALCITE-3101 discussed relevant information.

We should avoid pushing down some bad expressions, although they may be right. such as:
 * boolean expression
 * CAST *filed* NOT NULL

Currently, I fix it by the second solution. But, I also think the first solution is reasonable.

I need more advice.:)

 

> NonNull field shouldn't be pushed down into leaf of outer-join in 'ProjectJoinTransposeRule'
> --------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4982
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4982
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Xurenhe
>            Assignee: Xurenhe
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> I meet a bug, when applying rule of 'ProjectJoinTransposeRule'.
> Test Case:
> {code:java}
> @Test void testPushProjectPastLeftJoin2() {
>   final String sql = "select coalesce(d.name, b.job, '')\n"
>       + "from emp e\n"
>       + "left join bonus b on e.ename = b.ename\n"
>       + "left join dept d on e.deptno = d.deptno";
>   sql(sql).withRule(CoreRules.PROJECT_JOIN_TRANSPOSE).check();
> } {code}
> Exception Stack:
> {code:java}
> Suppressed: java.lang.AssertionError: Cannot add expression of different type to set:
> set type is RecordType(INTEGER NOT NULL DEPTNO, BOOLEAN NOT NULL EXPR$0, VARCHAR(10) NOT NULL EXPR$1) NOT NULL
> expression type is RecordType(INTEGER NOT NULL DEPTNO, BOOLEAN NOT NULL EXPR$0, VARCHAR(10) EXPR$1) NOT NULL
> set is rel#20:LogicalProject.(input=HepRelVertex#14,exprs=[$7, IS NOT NULL($10), CAST($10):VARCHAR(10) NOT NULL])
> expression is LogicalProject(DEPTNO=[$1], EXPR$0=[IS NOT NULL($3)], EXPR$1=[$4])
>   LogicalJoin(condition=[=($0, $2)], joinType=[left])
>     LogicalProject(ENAME=[$1], DEPTNO=[$7])
>       LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>     LogicalProject(ENAME=[$0], JOB=[$1], EXPR$1=[$1])
>       LogicalTableScan(table=[[CATALOG, SALES, BONUS]]) {code}
> I found that right with wrap not-null shouldn't be push down in one stage.
>  
> {code:java}
> // before applying rule
> LogicalProject(DEPTNO=[$7], EXPR$0=[IS NOT NULL($10)], EXPR$1=[CAST($10):VARCHAR(10) NOT NULL])
>   LogicalJoin(condition=[=($1, $9)], joinType=[left])
>     LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>     LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
> // after applying rule
> LogicalProject(DEPTNO=[$1], EXPR$0=[IS NOT NULL($3)], EXPR$1=[$4])
>   LogicalJoin(condition=[=($0, $2)], joinType=[left])
>     LogicalProject(ENAME=[$1], DEPTNO=[$7])
>       LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>     LogicalProject(ENAME=[$0], JOB=[$1], EXPR$1=[$1])
>       LogicalTableScan(table=[[CATALOG, SALES, BONUS]])
>  {code}
> `EXPR$1=[CAST($10):VARCHAR(10) NOT NULL]` should be pushed down, because of left-join.
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)