Skip to content

Commit e3b50d4

Browse files
committed
feat(tests): add edge cases to SLT tests for CTEs
- Implement self-reference IS NULL guard - Add tests for aggregate over nullable recursive output - Include derived projection/subquery filter scenarios - Test multi-column handling and type coercion nullability - Verify join functionality with null-sensitive predicates
1 parent e5920d4 commit e3b50d4

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

  • datafusion/sqllogictest/test_files

datafusion/sqllogictest/test_files/cte.slt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,65 @@ SELECT * FROM t
281281
----
282282
a Int64 YES
283283

284+
# recursive self-reference must not simplify away IS NULL guards when the
285+
# anchor term is nullable and the recursive term is non-null.
286+
query I rowsort
287+
WITH RECURSIVE t(a) AS (
288+
SELECT CAST(NULL AS INT) AS a
289+
UNION ALL
290+
SELECT 1 AS a FROM t WHERE a IS NULL
291+
)
292+
SELECT * FROM t
293+
----
294+
1
295+
NULL
296+
297+
# widened recursive nullability must survive aggregate physical planning.
298+
query III
299+
WITH RECURSIVE t(a) AS (
300+
SELECT 1 AS a
301+
UNION ALL
302+
SELECT CAST(NULL AS INT) AS a FROM t WHERE a IS NOT NULL
303+
)
304+
SELECT COUNT(*), COUNT(a), SUM(a) FROM t
305+
----
306+
2 1 1
307+
308+
# outer filters must still see widened nullability through a derived projection.
309+
query I
310+
WITH RECURSIVE t(a) AS (
311+
SELECT 1 AS a
312+
UNION ALL
313+
SELECT CAST(NULL AS INT) AS a FROM t WHERE a IS NOT NULL
314+
)
315+
SELECT x FROM (SELECT a AS x FROM t) WHERE x IS NULL
316+
----
317+
NULL
318+
319+
# per-column nullability widening must survive type coercion in multi-column
320+
# recursive terms.
321+
query II
322+
WITH RECURSIVE t(a, b) AS (
323+
SELECT 1::INT AS a, 2::INT AS b
324+
UNION ALL
325+
SELECT a + 1 AS a, CAST(NULL AS BIGINT) AS b FROM t WHERE a < 2
326+
)
327+
SELECT * FROM t WHERE b IS NULL
328+
----
329+
2 NULL
330+
331+
# join planning must preserve recursive output nullability for null-sensitive
332+
# predicates above the recursive query.
333+
query II
334+
WITH RECURSIVE t(a) AS (
335+
SELECT 1 AS a
336+
UNION ALL
337+
SELECT CAST(NULL AS INT) AS a FROM t WHERE a IS NOT NULL
338+
)
339+
SELECT t.a, u.b FROM t LEFT JOIN (SELECT 1 AS b) u ON t.a = u.b WHERE u.b IS NULL
340+
----
341+
NULL NULL
342+
284343
# deduplicating recursive CTE with two variables works
285344
query II
286345
WITH RECURSIVE ranges AS (

0 commit comments

Comments
 (0)