Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-27764 Feature Parity between PostgreSQL and Spark
  3. SPARK-28297

Handling outer links in CTE subquery expressions

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.1.0
    • None
    • SQL
    • None

    Description

      This query does work in Spark SQL:

      select (with cte(x) as (select 1) select x from cte) from test10
      

      But the following query can't handle the outer reference to the c column of test10 table:

      select (with cte(x) as (select c) select x from cte) from test10
      
      org.apache.spark.sql.AnalysisException: Expressions referencing the outer query are not supported outside of WHERE/HAVING clauses:
      Project [outer(c#41)]
      +- OneRowRelation
      ;;
      Project [scalar-subquery#167 [] AS scalarsubquery()#169]
      :  +- Project [x#168]
      :     +- SubqueryAlias `cte`
      :        +- Project [c#41 AS x#168]
      :           +- Project [outer(c#41)]
      :              +- OneRowRelation
      +- SubqueryAlias `default`.`test10`
         +- Relation[c#41] parquet
      
      

      where test10:

      CREATE TABLE test10 (c INTEGER);
      INSERT INTO test10 SELECT generate_sequence(1, 10);
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            petertoth Peter Toth
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: