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

Converting RelNode to SQL with CalciteSqlDialect gets wrong result while EnumerableIntersect is followed by EnumerableLimit

    XMLWordPrintableJSON

Details

    Description

      When I convert the following RelNode to SQL(with CalciteSqlDialect) in ToLogicalConverterTest.java:

      @Test void testIntersect() {
          final RelBuilder builder = builder();
          RelNode rel =
              builder.scan("DEPT")
                  .project(builder.field("DEPTNO"))
                  .scan("EMP")
                  .project(builder.field("DEPTNO"))
                  .intersect(true)
                  .limit(0, 2)
                  .build();
          System.out.println(new RelToSqlConverter(SqlDialect.DatabaseProduct.CALCITE.getDialect()).visitRoot(rel).asStatement());
      

      I get:

      SELECT *
      FROM SELECT `DEPTNO`
      FROM `scott`.`DEPT`
      INTERSECT ALL
      SELECT `DEPTNO`
      FROM `scott`.`EMP`
      FETCH NEXT 2 ROWS ONLY
      

      But the expected SQL should be:

      SELECT *
      FROM (SELECT `DEPTNO`
      FROM `scott`.`DEPT`
      INTERSECT ALL
      SELECT `DEPTNO`
      FROM `scott`.`EMP`)
      FETCH NEXT 2 ROWS ONLY
      

      Other SetOperators like UNION、MINUS can be converted correctly.

      Attachments

        Issue Links

          Activity

            People

              VAE ZheHu
              VAE ZheHu
              Votes:
              0 Vote for this issue
              Watchers:
              4 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