Skip to content

Commit 5b122cc

Browse files
AnjaliChoudhary99Anjali Choudhary
andauthored
Consolidate cte_quoted_reference.slt into cte.slt (#19862)
- Merged CTE reference resolution tests into main cte.slt file - Added CREATE TABLE statement for orders table used in tests - Fixed 3 case-sensitivity issues: changed 'WHERE N < 10' to 'WHERE n < 10' Fixes #19786 ## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #19786 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> This PR consolidates the small test file `cte_quoted_reference.slt` into the main `cte.slt` file as requested in issue #19786. The separate file was small enough that it didn't need to be maintained independently, and consolidating it improves code organization and maintainability. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> - Merged CTE reference resolution tests from `cte_quoted_reference.slt` into `cte.slt` - Added `CREATE TABLE orders AS VALUES (1), (2);` statement to support the merged tests - Fixed 3 pre-existing case-sensitivity bugs by changing `WHERE N < 10` to `WHERE n < 10` in recursive CTE tests - Deleted `cte_quoted_reference.slt` as it's now consolidated into the main file ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Yes, all changes are tested: - The consolidated tests from `cte_quoted_reference.slt` are now part of the `cte.slt` test suite - All sqllogictest tests pass successfully: `cargo test --test sqllogictests -- cte` - The case-sensitivity fixes ensure that field references match their definitions (lowercase `n`) ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> No, there are no user-facing changes. This is purely a test file reorganization that improves code maintainability without affecting DataFusion's functionality or API. <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> Co-authored-by: Anjali Choudhary <anjalicy@amazon.com>
1 parent 1a5c100 commit 5b122cc

2 files changed

Lines changed: 60 additions & 73 deletions

File tree

datafusion/sqllogictest/test_files/cte.slt

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,63 @@ physical_plan
4242
statement error DataFusion error: Error during planning: WITH query name "a" specified more than once
4343
WITH a AS (SELECT 1), a AS (SELECT 2) SELECT * FROM a;
4444

45+
statement ok
46+
CREATE TABLE orders AS VALUES (1), (2);
47+
48+
##########
49+
## CTE Reference Resolution
50+
##########
51+
52+
# These tests exercise CTE reference resolution with and without identifier
53+
# normalization. The session is configured with a strict catalog/schema provider
54+
# (see `datafusion/sqllogictest/src/test_context.rs`) that only provides the
55+
# `orders` table and panics on any unexpected table lookup.
56+
#
57+
# This makes it observable if DataFusion incorrectly treats a CTE reference as a
58+
# catalog lookup.
59+
#
60+
# Refs: https://github.com/apache/datafusion/issues/18932
61+
#
62+
# NOTE: This test relies on a strict catalog/schema provider registered in
63+
# `datafusion/sqllogictest/src/test_context.rs` that provides only the `orders`
64+
# table and panics on unexpected lookups.
65+
66+
statement ok
67+
set datafusion.sql_parser.enable_ident_normalization = true;
68+
69+
query I
70+
with barbaz as (select * from orders) select * from "barbaz";
71+
----
72+
1
73+
2
74+
75+
query I
76+
with BarBaz as (select * from orders) select * from "barbaz";
77+
----
78+
1
79+
2
80+
81+
query I
82+
with barbaz as (select * from orders) select * from barbaz;
83+
----
84+
1
85+
2
86+
87+
statement ok
88+
set datafusion.sql_parser.enable_ident_normalization = false;
89+
90+
query I
91+
with barbaz as (select * from orders) select * from "barbaz";
92+
----
93+
1
94+
2
95+
96+
query I
97+
with barbaz as (select * from orders) select * from barbaz;
98+
----
99+
1
100+
2
101+
45102
# Test disabling recursive CTE
46103
statement ok
47104
set datafusion.execution.enable_recursive_ctes = false;
@@ -996,7 +1053,7 @@ query TT
9961053
explain WITH RECURSIVE numbers AS (
9971054
select 1 as n
9981055
UNION ALL
999-
select n + 1 FROM numbers WHERE N < 10
1056+
select n + 1 FROM numbers WHERE n < 10
10001057
) select * from numbers;
10011058
----
10021059
logical_plan
@@ -1021,7 +1078,7 @@ query TT
10211078
explain WITH RECURSIVE numbers AS (
10221079
select 1 as n
10231080
UNION ALL
1024-
select n + 1 FROM numbers WHERE N < 10
1081+
select n + 1 FROM numbers WHERE n < 10
10251082
) select * from numbers;
10261083
----
10271084
logical_plan
@@ -1160,5 +1217,5 @@ query error DataFusion error: This feature is not implemented: Recursive CTEs ar
11601217
explain WITH RECURSIVE numbers AS (
11611218
select 1 as n
11621219
UNION ALL
1163-
select n + 1 FROM numbers WHERE N < 10
1220+
select n + 1 FROM numbers WHERE n < 10
11641221
) select * from numbers;

datafusion/sqllogictest/test_files/cte_quoted_reference.slt

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)