Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/cte-nested.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ SELECT (
SELECT * FROM t
);

-- Make sure CTE in subquery is scoped to that subquery rather than global
-- the 2nd half of the union should fail because the cte is scoped to the first half
SELECT * FROM
(
WITH cte AS (SELECT * FROM range(10))
SELECT * FROM cte WHERE id = 8
) a
UNION
SELECT * FROM cte;

-- CTE in CTE definition shadows outer
WITH
t AS (SELECT 1),
Expand Down
28 changes: 28 additions & 0 deletions sql/core/src/test/resources/sql-tests/results/cte-legacy.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ struct<scalarsubquery():int>
1


-- !query
SELECT * FROM
(
WITH cte AS (SELECT * FROM range(10))
SELECT * FROM cte WHERE id = 8
) a
UNION
SELECT * FROM cte
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "TABLE_OR_VIEW_NOT_FOUND",
"sqlState" : "42000",
"messageParameters" : {
"relationName" : "`cte`"
},
"queryContext" : [ {
"objectType" : "",
"objectName" : "",
"startIndex" : 120,
"stopIndex" : 122,
"fragment" : "cte"
} ]
}


-- !query
WITH
t AS (SELECT 1),
Expand Down
28 changes: 28 additions & 0 deletions sql/core/src/test/resources/sql-tests/results/cte-nested.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ struct<scalarsubquery():int>
1


-- !query
SELECT * FROM
(
WITH cte AS (SELECT * FROM range(10))
SELECT * FROM cte WHERE id = 8
) a
UNION
SELECT * FROM cte
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "TABLE_OR_VIEW_NOT_FOUND",
"sqlState" : "42000",
"messageParameters" : {
"relationName" : "`cte`"
},
"queryContext" : [ {
"objectType" : "",
"objectName" : "",
"startIndex" : 120,
"stopIndex" : 122,
"fragment" : "cte"
} ]
}


-- !query
WITH
t AS (SELECT 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ struct<scalarsubquery():int>
1


-- !query
SELECT * FROM
(
WITH cte AS (SELECT * FROM range(10))
SELECT * FROM cte WHERE id = 8
) a
UNION
SELECT * FROM cte
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "TABLE_OR_VIEW_NOT_FOUND",
"sqlState" : "42000",
"messageParameters" : {
"relationName" : "`cte`"
},
"queryContext" : [ {
"objectType" : "",
"objectName" : "",
"startIndex" : 120,
"stopIndex" : 122,
"fragment" : "cte"
} ]
}


-- !query
WITH
t AS (SELECT 1),
Expand Down