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

NullPointerException in ProjectCorrelateTransposeRule

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.38.0
    • None
    • core
    • None

    Description

      The following RelOptRulesTest causes an exception in Calcite:

        @Test void testLateralTranspose() {
          final String sql = "WITH "
              + "  t1(a, ts) AS (VALUES('a', 1)),"
              + "  t2(a, ts, x) AS (SELECT ename as a, empno as ts, mgr as x FROM emp)\n"
              + "SELECT * FROM t1\n"
              + "LEFT JOIN LATERAL (\n"
              + "    SELECT x FROM t2\n"
              + "    WHERE t2.a = t1.a AND t2.ts <= t1.ts\n"
              + "    LIMIT 1\n"
              + ") ON true\n"
              + "LEFT JOIN LATERAL (\n"
              + "    SELECT x\n"
              + "    FROM t2\n"
              + "    WHERE t2.a = t1.a\n"
              + ") ON true";
          sql(sql).withDecorrelate(true).withRule(CoreRules.PROJECT_CORRELATE_TRANSPOSE).check();
        }
      

      Here is the top of the stack trace:

      java.lang.NullPointerException: no entry for field 1 in {2=2, 3=3}
      	at java.base/java.util.Objects.requireNonNull(Objects.java:360)
      	at org.apache.calcite.rel.rules.ProjectCorrelateTransposeRule$RexFieldAccessReplacer.visitFieldAccess(ProjectCorrelateTransposeRule.java:178)
      	at org.apache.calcite.rel.rules.ProjectCorrelateTransposeRule$RexFieldAccessReplacer.visitFieldAccess(ProjectCorrelateTransposeRule.java:146)
      	at org.apache.calcite.rex.RexFieldAccess.accept(RexFieldAccess.java:93)
      	at org.apache.calcite.rex.RexShuttle.visitList(RexShuttle.java:167)
      	at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:119)
      	at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:38)
      	at org.apache.calcite.rex.RexCall.accept(RexCall.java:208)
      	at org.apache.calcite.rex.RexShuttle.visitList(RexShuttle.java:167)
      	at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:119)
      	at org.apache.calcite.rex.RexShuttle.visitCall(RexShuttle.java:38)
      	at org.apache.calcite.rex.RexCall.accept(RexCall.java:208)
      	at org.apache.calcite.rex.RexShuttle.apply(RexShuttle.java:287)
      	at org.apache.calcite.rel.core.Filter.accept(Filter.java:129)
      	at org.apache.calcite.rel.rules.ProjectCorrelateTransposeRule$RelNodesExprsHandler.visitChild(ProjectCorrelateTransposeRule.java:199)
      	at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:97)
      	at org.apache.calcite.rel.logical.LogicalFilter.accept(LogicalFilter.java:158)
      	at org.apache.calcite.rel.RelShuttleImpl.visitChild(RelShuttleImpl.java:57)
      	at org.apache.calcite.rel.rules.ProjectCorrelateTransposeRule$RelNodesExprsHandler.visitChild(ProjectCorrelateTransposeRule.java:198)
      	at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:105)
      	at org.apache.calcite.rel.logical.LogicalProject.accept(LogicalProject.java:178)
      	at org.apache.calcite.rel.RelShuttleImpl.visitChild(RelShuttleImpl.java:57)
      	at org.apache.calcite.rel.rules.ProjectCorrelateTransposeRule$RelNodesExprsHandler.visitChild(ProjectCorrelateTransposeRule.java:198)
      	at org.apache.calcite.rel.RelShuttleImpl.visitChildren(RelShuttleImpl.java:71)
      	at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:129)
      	at org.apache.calcite.rel.logical.LogicalSort.accept(LogicalSort.java:86)
      	at org.apache.calcite.rel.RelShuttleImpl.visitChild(RelShuttleImpl.java:57)
      	at org.apache.calcite.rel.rules.ProjectCorrelateTransposeRule$RelNodesExprsHandler.visitChild(ProjectCorrelateTransposeRule.java:198)
      	at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:105)
      	at org.apache.calcite.rel.logical.LogicalProject.accept(LogicalProject.java:178)
      	at org.apache.calcite.rel.rules.ProjectCorrelateTransposeRule.onMatch(ProjectCorrelateTransposeRule.java:120)
      	at org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:336)
      	at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:556)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            mbudiu Mihai Budiu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: