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

Alessandro Solimando edited comment on CALCITE-6501 at 7/25/24 9:53 AM:
------------------------------------------------------------------------

I agree, and at the same time the rewrite seems possible as it's just a 
syntactic rewrite (I guess that's what you wanted to assess in the first place).

Nullability information gets lost in this case, it would be interesting to 
investigate and fix it, as we are losing rewrite opportunities.

EDIT: we were writing at the same time so I didn't see your message. I think 
the two discussions shouldn't conflate. Replacing the assertion with returning 
null vs understanding why we fail at this correct unification. For the latter I 
suggest to file a separate ticket with more details like the plans and your 
consideration. For the former, I think returning null is good, and turning the 
assert into a debug information (it was useful to make us realize what's 
happening). WDYT?


was (Author: asolimando):
I agree, and at the same time the rewrite seems possible as it's just a 
syntactic rewrite (I guess that's what you wanted to assess in the first place).

Nullability information gets lost in this case, it would be interesting to 
investigate and fix it, as we are losing rewrite opportunities.

> Assertion Error in JoinUnifyRule Due to Type Mismatch
> -----------------------------------------------------
>
>                 Key: CALCITE-6501
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6501
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: kate
>            Priority: Minor
>
> In some cases, there is an assertion failure during the unifyRule rewriting 
> process due to a type mismatch. If we can't rewrite it, we'd better return 
> null instead of assert.
> example:
> {code:java}
> @Test
> public void testJoinOnCalcToJoin3011()
> {
>   String mv = ""
>       + "select \"emps\".\"empid\", \"emps\".\"deptno\", \"depts\".\"deptno\" 
> from\n"
>       + "\"emps\" right join \"depts\"\n"
>       + "on \"emps\".\"deptno\" = \"depts\".\"deptno\"";
>   String query = ""
>       + "select \"A\".\"empid\", \"A\".\"a\", \"A\".\"deptno\", 
> \"depts\".\"deptno\" from\n"
>       + " (select \"empid\", \"deptno\", \"deptno\" \"a\" from \"emps\") A"
>       + " right join \"depts\"\n"
>       + "on \"A\".\"deptno\" = \"depts\".\"deptno\"";
>   sql(mv, query).noMat();
> } {code}
> Trace:
> {code:java}
> type mismatch:type1:JavaType(int) NOT NULLtype2:JavaType(class 
> java.lang.Integer)java.lang.AssertionError: type mismatch:type1:JavaType(int) 
> NOT NULLtype2:JavaType(class java.lang.Integer) at 
> org.apache.calcite.util.Litmus.lambda$static$0(Litmus.java:31) at 
> org.apache.calcite.plan.RelOptUtil.eq(RelOptUtil.java:2204) at 
> org.apache.calcite.rex.RexProgramBuilder$RegisterInputShuttle.visitInputRef(RexProgramBuilder.java:949)
>  at 
> org.apache.calcite.rex.RexProgramBuilder$RegisterInputShuttle.visitInputRef(RexProgramBuilder.java:927)
>  at org.apache.calcite.rex.RexInputRef.accept(RexInputRef.java:125) at 
> org.apache.calcite.rex.RexProgramBuilder.registerInput(RexProgramBuilder.java:303)
>  at 
> org.apache.calcite.rex.RexProgramBuilder.addProject(RexProgramBuilder.java:213)
>  at org.apache.calcite.rex.RexProgram.create(RexProgram.java:235) at 
> org.apache.calcite.rex.RexProgram.create(RexProgram.java:204) at 
> org.apache.calcite.plan.SubstitutionVisitor$JoinOnLeftCalcToJoinUnifyRule.apply(SubstitutionVisitor.java:1265)
>  at 
> org.apache.calcite.plan.SubstitutionVisitor.go(SubstitutionVisitor.java:589) 
> at 
> org.apache.calcite.plan.SubstitutionVisitor.go(SubstitutionVisitor.java:523) 
> at 
> org.apache.calcite.test.MaterializedViewSubstitutionVisitorTest$1.optimize(MaterializedViewSubstitutionVisitorTest.java:88)
>  at 
> org.apache.calcite.test.MaterializedViewTester.checkNoMaterialize(MaterializedViewTester.java:94)
>  at 
> org.apache.calcite.test.MaterializedViewFixture.noMat(MaterializedViewFixture.java:60)
>  at {code}
>  
>  
>  
>  



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

Reply via email to