Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-6501

Assertion Error in JoinUnifyRule Due to Type Mismatch

    XMLWordPrintableJSON

Details

    Description

      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:

      @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();
      } 

      Trace:

      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 

       

       

       
       

      Attachments

        1. image-2024-07-25-22-05-23-957.png
          86 kB
          suibianwanwan

        Issue Links

          Activity

            People

              Unassigned Unassigned
              suibianwanwan33 suibianwanwan
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: