You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Jarno Rajala (Jira)" <ji...@apache.org> on 2022/04/06 10:14:00 UTC

[jira] [Comment Edited] (SPARK-38404) Spark does not find CTE inside nested CTE

    [ https://issues.apache.org/jira/browse/SPARK-38404?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17518011#comment-17518011 ] 

Jarno Rajala edited comment on SPARK-38404 at 4/6/22 10:13 AM:
---------------------------------------------------------------

I've experienced the same bug in Databricks. I've also confirmed that the issue can be reproduced with the _spark-sql_ tool from Spark 3.2.1 (from [https://spark.apache.org/downloads.html]), but the issue does not exist in Spark 3.1.2.

This issue causes serious problems for me, as I'm using _dbt_ macros to augment SQL queries and flattening nested CTEs is not an uncomplicated workaround.

Setting *spark.sql.legacy.ctePrecedencePolicy = CORRECTED* does not seem to affect this behaviour.


was (Author: JIRAUSER287684):
I've experienced the same bug in Databricks. I've also confirmed that the issue can be reproduced with the _spark-sql_ tool from Spark 3.2.1 (from https://spark.apache.org/downloads.html), but the issue does not exist in Spark 3.1.2.

This issue causes serious problems for me, as I'm using _dbt_ macros to augment SQL queries and flattening nested CTEs is not an uncomplicated workaround.

> 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
>            Priority: Minor
>
> 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.1#820001)

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