[ 
https://issues.apache.org/jira/browse/SPARK-38404?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Wenchen Fan updated SPARK-38404:
--------------------------------
    Fix Version/s: 3.3.1

> Spark does not find CTE inside nested CTE
> -----------------------------------------
>
>                 Key: SPARK-38404
>                 URL: https://issues.apache.org/jira/browse/SPARK-38404
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 3.2.0, 3.2.1
>         Environment: Tested on:
>  * MacOS Monterrey 12.2.1 (21D62)
>  * python 3.9.10
>  * pip 22.0.3
>  * pyspark 3.2.0 & 3.2.1 (SQL query does not work) and pyspark 3.0.1 and 
> 3.1.3 (SQL query works)
>            Reporter: Joan Heredia Rius
>            Assignee: Peter Toth
>            Priority: Minor
>             Fix For: 3.4.0, 3.3.1
>
>
> Hello! 
> Seems that when defining CTEs and using them inside another CTE in Spark SQL, 
> Spark thinks the inner call for the CTE is a table or view, which is not 
> found and then it errors with `Table or view not found: <CTE name>`
> h3. Steps to reproduce
>  # `pip install pyspark==3.2.0` (also happens with 3.2.1)
>  # start pyspark console by typing `pyspark` in the terminal
>  # Try to run the following SQL with `spark.sql(sql)`
>  
> {code:java}
>   WITH mock_cte__users    AS (
>            SELECT 1 AS id
>        ),
>        model_under_test          AS (
>              WITH users    AS (
>                       SELECT *
>                         FROM mock_cte__users
>                   )
>            SELECT *
>              FROM users
>        )
> SELECT *
>   FROM model_under_test;{code}
> Spark will fail with 
>  
> {code:java}
> pyspark.sql.utils.AnalysisException: Table or view not found: 
> mock_cte__users; line 8 pos 29; {code}
> I don't know if this is a regression or an expected behavior of the new 3.2.* 
> versions. This fix introduced in 3.2.0 might be related: 
> https://issues.apache.org/jira/browse/SPARK-36447
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to