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

Unparsing LIMIT without ORDER BY generates invalid SQL after validation

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.0
    • Fix Version/s: 1.8.0
    • Component/s: core
    • Labels:
      None

      Description

      The context of the problem is the validation of queries with a LIMIT clause but no ORDER BY, e.g. "SELECT c FROM t LIMIT 2".

      The problem does not show up at parsing time but when running a validator. The generated AST includes an ORDER BY operand with an empty column list.

      When building a SQL query out of the validated AST, an ORDER BY clause is inserted before the LIMIT/FETCH clause, e.g "SELECT c FROM t ORDER BY LIMIT 2". This SQL query is not valid.

        Activity

        Hide
        julianhyde Julian Hyde added a comment -

        Agreed, this is a bug. Emmanuel Bastien, Are you working on a fix for this?

        Show
        julianhyde Julian Hyde added a comment - Agreed, this is a bug. Emmanuel Bastien , Are you working on a fix for this?
        Hide
        ebastien Emmanuel Bastien (Inactive) added a comment -

        I'll submit a PR later today, including the additional test cases you mentioned on the mailing list.

        Show
        ebastien Emmanuel Bastien (Inactive) added a comment - I'll submit a PR later today, including the additional test cases you mentioned on the mailing list.
        Hide
        ebastien Emmanuel Bastien (Inactive) added a comment -

        PR #230 submitted

        Show
        ebastien Emmanuel Bastien (Inactive) added a comment - PR #230 submitted
        Hide
        julianhyde Julian Hyde added a comment -
        Show
        julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/0d2eae5b . Thanks for the PR, Emmanuel Bastien !
        Hide
        julianhyde Julian Hyde added a comment -

        Resolved in release 1.8.0 (2016-06-13).

        Show
        julianhyde Julian Hyde added a comment - Resolved in release 1.8.0 (2016-06-13).

          People

          • Assignee:
            ebastien Emmanuel Bastien (Inactive)
            Reporter:
            ebastien Emmanuel Bastien (Inactive)
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development