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

When translating ORDER BY in OVER, use the session's default null collation (e.g. NULLS LAST)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.32.0
    • 1.33.0
    • core
    • None

    Description

      The connection configuration  string defaultNullCollation=LOW can't take effect for order by in over clause.  When translating ORDER BY in OVER, Calcite should use the session's default null collation (e.g. NULLS LAST).

      After debug, I found that the  convertSortExpression in SqlToRelConverter.convertOver was changed to bb::sortToRex and the bb::sortToRex didn't read default configuration.

      https://github.com/apache/calcite/blob/c945b7f49b99538748c871557f6ac80957be2b6e/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L2247

      Also, The corresponding test case is incorrect at  org.apache.calcite.test.SqlToRelConverterTest#testUserDefinedOrderByOver .

      sql :

      select deptno,rank() over(partition by empno order by deptno) 
        from emp 
        order by row_number() over(partition by empno order by deptno) 

      correct result

      LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
        LogicalSort(sort0=[$2], dir0=[ASC-nulls-first])
          LogicalProject(DEPTNO=[$7], EXPR$1=[RANK() OVER (PARTITION BY $0 ORDER BY $7 NULLS FIRST)], EXPR$2=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY $7 NULLS FIRST)])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]]) 

      but was 

      LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
        LogicalSort(sort0=[$2], dir0=[ASC-nulls-first])
          LogicalProject(DEPTNO=[$7], EXPR$1=[RANK() OVER (PARTITION BY $0 ORDER BY $7)], EXPR$2=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY $7)])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]]) 

      Attachments

        Issue Links

          Activity

            People

              julianhyde Julian Hyde
              shpodg shanpo liu
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: