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

RelToSql converter fails when semi-join is under a 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 testSemiJoinUnderJoin() {
        final RelBuilder builder = relBuilder();
        final RelNode base = builder
            .scan("EMP")
            .scan("EMP")
            .join(
                JoinRelType.SEMI, builder.equals(
                    builder.field(2, 0, "EMPNO"),
                    builder.field(2, 1, "EMPNO")))
            .build();
        final RelNode root = builder
            .scan("DEPT")
            .push(base)
            .join(
                JoinRelType.INNER, builder.equals(
                    builder.field(2, 1, "DEPTNO"),
                    builder.field(2, 0, "DEPTNO")))
            .project(builder.field("DEPTNO"))
            .build();
        toSql(root);
      } 

      The exception is:

      alias
      java.lang.NullPointerException: alias
          at java.base/java.util.Objects.requireNonNull(Objects.java:233)
          at org.apache.calcite.rel.rel2sql.SqlImplementor.collectAliases(SqlImplementor.java:493)
          at org.apache.calcite.rel.rel2sql.SqlImplementor.collectAliases(SqlImplementor.java:491)
          at org.apache.calcite.rel.rel2sql.SqlImplementor.result(SqlImplementor.java:476)
          at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:246) 

      Cause of failure seems to be that `RelToSqlConverter::visitAntiOrSemiJoin` rewrites semi-join as select with no associated alias.

      Attachments

        Issue Links

          Activity

            People

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