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

CTE as subquery without alias doesn't have correct alias setup

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.34.0, 1.35.0
    • 1.36.0
    • core

    Description

      SELECT
        a,
        b
      FROM (
        WITH
          sub AS (
          SELECT
            1 AS a,
            2 AS b)
        SELECT
          *
        FROM
          sub)
      WHERE
        a IS NOT null
      
      

      It will generate the following SQL statement after validation

      SELECT
        EXPR$0.a,
        EXPR$0.b
      FROM (
        WITH
          sub AS (
          SELECT
            1 AS a,
            2 AS b)
        SELECT
          sub.a AS a, sub.b AS b
        FROM
          sub)
      WHERE
        EXPR$0.a IS NOT null
      
      

      The validated SQL become invalid since there is no EXPR$0 alias append for the SqlWith sub query but used in the expression outside.

      Attachments

        Issue Links

          Activity

            People

              wenruimeng Wenrui Meng
              wenruimeng Wenrui Meng
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: