Skip to content
Merged
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
63 changes: 60 additions & 3 deletions datafusion/sqllogictest/test_files/cte.slt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,63 @@ physical_plan
statement error DataFusion error: Error during planning: WITH query name "a" specified more than once
WITH a AS (SELECT 1), a AS (SELECT 2) SELECT * FROM a;

statement ok
CREATE TABLE orders AS VALUES (1), (2);

##########
## CTE Reference Resolution
##########

# These tests exercise CTE reference resolution with and without identifier
# normalization. The session is configured with a strict catalog/schema provider
# (see `datafusion/sqllogictest/src/test_context.rs`) that only provides the
# `orders` table and panics on any unexpected table lookup.
#
# This makes it observable if DataFusion incorrectly treats a CTE reference as a
# catalog lookup.
#
# Refs: https://github.com/apache/datafusion/issues/18932
#
# NOTE: This test relies on a strict catalog/schema provider registered in
# `datafusion/sqllogictest/src/test_context.rs` that provides only the `orders`
# table and panics on unexpected lookups.

statement ok
set datafusion.sql_parser.enable_ident_normalization = true;

query I
with barbaz as (select * from orders) select * from "barbaz";
----
1
2

query I
with BarBaz as (select * from orders) select * from "barbaz";
----
1
2

query I
with barbaz as (select * from orders) select * from barbaz;
----
1
2

statement ok
set datafusion.sql_parser.enable_ident_normalization = false;

query I
with barbaz as (select * from orders) select * from "barbaz";
----
1
2

query I
with barbaz as (select * from orders) select * from barbaz;
----
1
2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to ensure we cleanup the orders table to ensure this section of tests are isolated

# Test disabling recursive CTE
statement ok
set datafusion.execution.enable_recursive_ctes = false;
Expand Down Expand Up @@ -996,7 +1053,7 @@ query TT
explain WITH RECURSIVE numbers AS (
select 1 as n
UNION ALL
select n + 1 FROM numbers WHERE N < 10
select n + 1 FROM numbers WHERE n < 10
) select * from numbers;
----
logical_plan
Expand All @@ -1021,7 +1078,7 @@ query TT
explain WITH RECURSIVE numbers AS (
select 1 as n
UNION ALL
select n + 1 FROM numbers WHERE N < 10
select n + 1 FROM numbers WHERE n < 10
) select * from numbers;
----
logical_plan
Expand Down Expand Up @@ -1160,5 +1217,5 @@ query error DataFusion error: This feature is not implemented: Recursive CTEs ar
explain WITH RECURSIVE numbers AS (
select 1 as n
UNION ALL
select n + 1 FROM numbers WHERE N < 10
select n + 1 FROM numbers WHERE n < 10
) select * from numbers;
70 changes: 0 additions & 70 deletions datafusion/sqllogictest/test_files/cte_quoted_reference.slt

This file was deleted.