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

SqlToRelConverter#substituteSubQuery fails with NullPointerException when converting SqlUpdate.

    XMLWordPrintableJSON

    Details

      Description

      Current code fails below test

      // code placeholder
      @Test public void testUpdateSubQueryWithIn1() {
        final String sql = "update emp\n"
                + "set empno = 1 where emp.empno in (\n"
                + "  select emp.empno from emp where emp.empno=2)";
        sql(sql).ok();
      }
      
      java.lang.NullPointerExceptionjava.lang.NullPointerException at org.apache.calcite.rel.logical.LogicalJoin.create(LogicalJoin.java:146) at org.apache.calcite.rel.logical.LogicalJoin.create(LogicalJoin.java:163) at org.apache.calcite.sql2rel.SqlToRelConverter.substituteSubQuery(SqlToRelConverter.java:1130) at org.apache.calcite.sql2rel.SqlToRelConverter.replaceSubQueries(SqlToRelConverter.java:1014) at org.apache.calcite.sql2rel.SqlToRelConverter.convertUpdate(SqlToRelConverter.java:3574) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:3176) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:563) at org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:616) at org.apache.calcite.test.SqlToRelTestBase$TesterImpl.assertConvertsTo(SqlToRelTestBase.java:731) at org.apache.calcite.test.SqlToRelConverterTest$Sql.convertsTo(SqlToRelConverterTest.java:3601) at org.apache.calcite.test.SqlToRelConverterTest$Sql.ok(SqlToRelConverterTest.java:3593)
      

       In above case, Subquery is used as SqlUpdate#condition, when converting and trying to replace the subquery in SqlUpdate#condition, BalckBoard#root is null and it makes no sense to do the subquery substitution.

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jinxing6042@126.com jin xing
                Reporter:
                jinxing6042@126.com jin xing
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m