You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CTE: Non-recursive term and recursive term should have the same schema #9794
Currently, DataFusion allows their schemas to be different, which may lead to some query failures or incorrect results.
To Reproduce
Run queries on CLI
DataFusion CLI v36.0.0
❯ WITH RECURSIVE my_cte AS(
SELECT 1::int AS a
UNION ALL
SELECT a+2 FROM my_cte WHERE a<3
) SELECT * FROM my_cte;
Arrow error: Invalid argument error: Invalid comparison operation: Int64 < Int32
❯ WITH RECURSIVE my_cte AS (
SELECT 1::bigint AS a
UNION ALL
SELECT a+2, 'a','c' FROM my_cte WHERE a<3
) SELECT * FROM my_cte;
+---+---+---+
| a |||
+---+---+---+
| 1 |||| 3 | a | c |
+---+---+---+
2 rows in set. Query took 0.020 seconds.
❯ WITH RECURSIVE my_cte AS (
SELECT 1 AS a
UNION ALL
SELECT 'abc' FROM my_cte WHERE CAST(a AS text) !='abc'
) SELECT * FROM my_cte;
+-----+
| a |
+-----+
| 1 || abc |
+-----+
2 rows in set. Query took 0.012 seconds.
Expected behavior
Query 1 should be successful.
Query 2 and query 3 should fail, because the number of columns and the data types between the output rows are not the same.
Activity
jonahgao commentedon Mar 25, 2024
take
fix: validate recursive CTE column coercion (apache#25956)