Avery Qi created SPARK-58779:
--------------------------------

             Summary: InlineCTE throw errors when it is running in 
checkAnalysis for UDTF body having CTERelationRef but without CTERelationDef
                 Key: SPARK-58779
                 URL: https://issues.apache.org/jira/browse/SPARK-58779
             Project: Spark
          Issue Type: Bug
          Components: Optimizer, SQL
    Affects Versions: 4.2.0, 4.1.0, 4.3.0, 4.4.0
            Reporter: Avery Qi


For the below example:
```

CREATE TEMPORARY FUNCTION my_tvf(a INT, b INT) RETURNS TABLE(x INT)
RETURN SELECT a + b AS x;
      
WITH cte AS (SELECT 1 AS c1, 2 AS c2)
SELECT * FROM my_tvf((SELECT c1 FROM cte), (SELECT c2 FROM cte));

```
`ResolveSQLTableFunctions` calls `checkAnalysis` on the function body. The 
`checkAnalysis` then calls `inlineCTE` on the function body. But the function 
body only contains CTERelationRef, no CTERelationDef.

InlineCTE then throws NoSuchElementException error when it encounter 
CTERelationRef but its cteId is not recorded in the cteMap.

Spark need to either throws a clear Analysis Exception for this case or 
inlineCTE called in checkAnalysis should tolerant this.



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to