[ https://issues.apache.org/jira/browse/CALCITE-2455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16577727#comment-16577727 ]
Julian Hyde commented on CALCITE-2455: -------------------------------------- [~danny0405], Maybe you need to make sure the email address for your github account matches the email address for your commits. Currently when I go to [https://github.com/apache/calcite/pull/782/commits] github doesn't think that yuzhao.cyz is a github user. Compare to [https://github.com/apache/calcite/pull/779/commits], for example, where "snuyanzin" links to [https://github.com/apache/calcite/commits?author=snuyanzin]. I agree with [~vlsi] that {{simplify}} should be allowed to strengthen the type. If people want to keep the same type, they should call {{simplifyPreservingType}} (the javadoc incorrectly says that it is only for boolean expressions). {{simplifyCase}} is wrong to try to keep the same type. I just needed to patch {{ReduceExpressionsRule}} to make everything work: {noformat} diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java index a3ae9d91f..821a623e1 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java @@ -788,7 +788,7 @@ protected static RexNode substitute(RexCall call, int ordinal, RexNode node) { } node = super.visitCall(call); if (node != call) { - node = simplify.withUnknownAsFalse(false).simplify(node); + node = simplify.withUnknownAsFalse(false).simplifyPreservingType(node); } return node; } diff --git a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java index 085380c34..a5e5810ba 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java +++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java @@ -586,11 +586,7 @@ private RexNode simplifyCase(RexCall call) { } assert newOperands.size() % 2 == 1; if (newOperands.size() == 1 || values.size() == 1) { - final RexNode last = Util.last(newOperands); - if (!call.getType().equals(last.getType())) { - return rexBuilder.makeAbstractCast(call.getType(), last); - } - return last; + return Util.last(newOperands); } trueFalse: if (call.getType().getSqlTypeName() == SqlTypeName.BOOLEAN) { {noformat} > simplifyCoalesce of constant should match nullability > ----------------------------------------------------- > > Key: CALCITE-2455 > URL: https://issues.apache.org/jira/browse/CALCITE-2455 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.17.0 > Reporter: Yuzhao Chen > Assignee: Julian Hyde > Priority: Major > Fix For: 1.18.0 > > > After CALCITE-2227, we will not replace Coalesce to Case When for natural > join, when we use ReduceExpressionRule for our plan for Coalesce with > constant, the nullability will chage( from nullable to notnull), this will > cause VolcanoPlanner to throw error. > Should i fix this? or we should not use this rule in VolcanoPlanner? > This is the error thrown sql : > {code:java} > select * from lateral (select * from scott_emp) as e > join (table scott_dept) using (deptno) > where e.deptno = 10 {code} > The plan before ReduceExpressionRule: > {code:java} > LogicalProject(deptno=[COALESCE($7, $8)], empno=[$0], ename=[$1], job=[$2], > mgr= [$3], hiredate=[$4], sal=[$5], comm=[$6], dname=[$9], loc=[$10]) > +- LogicalFilter(condition=[=($7, 10)]) > +- LogicalJoin(condition=[=($7, $8)], joinType=[inner]) > :- LogicalProject(empno=[$0], ename=[$1], job=[$2], mgr=[$3], hiredate=[$4], > sal=[$5], comm=[$6], deptno=[$7]) > : +- LogicalTableScan(table=[[scott_emp]]) > +- LogicalProject(deptno=[$0], dname=[$1], loc=[$2]) > +- LogicalTableScan(table=[[scott_dept]]) > {code} > The plan after: > {code:java} > LogicalProject(deptno=[10], empno=[$0], ename=[$1], job=[$2], mgr=[$3], > hiredate=[$4], sal=[$5], comm=[$6], dname=[$9], loc=[$10]) > +- LogicalFilter(condition=[=($7, 10)]) > +- LogicalJoin(condition=[=($7, $8)], joinType=[inner]) > :- LogicalProject(empno=[$0], ename=[$1], job=[$2], mgr=[$3], hiredate=[$4], > sal=[$5], comm=[$6], deptno=[$7]) > : +- LogicalTableScan(table=[[scott_emp]]) > +- LogicalProject(deptno=[$0], dname=[$1], loc=[$2]) > +- LogicalTableScan(table=[[scott_dept]]) > {code} > We can see that the deptno's nullability changes from nullable to not null. > And we encounter an type error when using ReduceExpressionRule in > VolcanoPlanner. -- This message was sent by Atlassian JIRA (v7.6.3#76005)