Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-3651

Window function should not be allowed in order by clause of over clause of window function

    XMLWordPrintableJSON

Details

    Description

      Should not parse and throw an error according to SQL standard.
      "ISO/IEC 9075-2:2011(E) 7.11 <window clause>"
      d) If WDX has a window ordering clause, then WDEF shall not specify <window order clause> (hope I'm reading it correctly)

      SELECT rank() OVER (ORDER BY rank() OVER (ORDER BY c1)) from t1;
      

      Instead, drill returns result:

      0: jdbc:drill:schema=dfs> SELECT rank() OVER (ORDER BY rank() OVER (ORDER BY c1)) from t1;
      +---------+
      | EXPR$0  |
      +---------+
      | 1       |
      | 2       |
      | 3       |
      | 4       |
      | 5       |
      | 6       |
      | 7       |
      | 8       |
      | 9       |
      | 10      |
      +---------+
      10 rows selected (0.336 seconds)
      

      Postgres throws an error in this case:

      postgres=# SELECT rank() OVER (ORDER BY rank() OVER (ORDER BY c1)) from t1;
      ERROR:  window functions are not allowed in window definitions
      LINE 1: SELECT rank() OVER (ORDER BY rank() OVER (ORDER BY c1)) from...
      

      Courtesy of postgres test suite.

      Attachments

        Activity

          People

            Unassigned Unassigned
            vicky Victoria Markman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: