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

RelToSql converter fails when SELECT * is under a semi-join node

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.32.0
    • 1.33.0
    • None

    Description

      The following test case would fail if added to RelToSqlConverterTest.java:

      @Test void testUnionUnderSemiJoinNode() {
        final RelBuilder builder = relBuilder();
        final RelNode base = builder
            .scan("EMP")
            .scan("EMP")
            .union(true)
            .build();
        final RelNode root = builder
            .push(base)
            .scan("DEPT")
            .join(
                JoinRelType.SEMI, builder.equals(
                    builder.field(2, 1, "DEPTNO"),
                    builder.field(2, 0, "DEPTNO")))
            .project(builder.field("DEPTNO"))
            .build();
        toSql(root);
      } 

      The exception is:

      Index 7 out of bounds for length 1
      java.lang.IndexOutOfBoundsException: Index 7 out of bounds for length 1
          at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
          at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
          at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
          at java.base/java.util.Objects.checkIndex(Objects.java:359)
          at java.base/java.util.ArrayList.get(ArrayList.java:427)
          at org.apache.calcite.sql.SqlNodeList.get(SqlNodeList.java:160)
          at org.apache.calcite.rel.rel2sql.RelToSqlConverter$AliasReplacementShuttle.visit(RelToSqlConverter.java:197)
          at org.apache.calcite.rel.rel2sql.RelToSqlConverter$AliasReplacementShuttle.visit(RelToSqlConverter.java:179)
          at org.apache.calcite.sql.SqlIdentifier.accept(SqlIdentifier.java:324)
          at org.apache.calcite.sql.util.SqlShuttle$CallCopyingArgHandler.visitChild(SqlShuttle.java:134)
          at org.apache.calcite.sql.util.SqlShuttle$CallCopyingArgHandler.visitChild(SqlShuttle.java:101)
          at org.apache.calcite.sql.SqlOperator.acceptCall(SqlOperator.java:954)
          at org.apache.calcite.sql.util.SqlShuttle.visit(SqlShuttle.java:68)
          at org.apache.calcite.sql.util.SqlShuttle.visit(SqlShuttle.java:41)
          at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:161)
          at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitAntiOrSemiJoin(RelToSqlConverter.java:261) 

      What happens is that `AliasReplacementShuttle` expects a select list as a source of replacement, but cannot handle a case when select node has a `select *` form.

      In case of current test, `union` is transformed to `select *` form before semi-join handling occurs.

      Attachments

        Issue Links

          Activity

            People

              jiajunbernoulli Jiajun Xie
              lchistov1987 Leonid Chistov
              Votes:
              0 Vote for this issue
              Watchers:
              6 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 - 0.5h
                  0.5h