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

JDBC adapter should retain parentheses if a query in a UNION has a LIMIT clause

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.31.0
    • core
    • None

    Description

      The JDBC adapter, when generating SQL, should retain parentheses if one of the inputs to a set operator (e.g. UNION) has an LIMIT clause.

      In standard SQL, the operand of UNION should not have LIMIT or ORDER BY. So parse will fail in SqlParserTetest#testLimitUnion and SqlParserTetest#OrderUnion.

      When users use parentheses, most engines allow it. See the discussion: CALCITE-1892.

      For simple example, parentheses control the scope of the limit

      select "product_id" from "product"
      union all
      (select "product_id" from "product" limit 10)

      unparseBinarySyntax will miss parentheses, this change will affect semantics

      SELECT \"product_id\" FROM \"foodmart\".\"product\" 
      UNION ALL 
      SELECT \"product_id\" FROM \"foodmart\".\"product\" 
      FETCH NEXT 10 ROWS ONLY  -- Affect semantics

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jiajunbernoulli Jiajun Xie
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: