Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTE: Non-recursive term and recursive term should have the same schema #9794

Closed
jonahgao opened this issue Mar 25, 2024 · 1 comment · Fixed by #9795
Closed

CTE: Non-recursive term and recursive term should have the same schema #9794

jonahgao opened this issue Mar 25, 2024 · 1 comment · Fixed by #9795
Assignees
Labels
bug Something isn't working

Comments

@jonahgao
Copy link
Member

Describe the bug

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.

Additional context

No response

@jonahgao jonahgao added the bug Something isn't working label Mar 25, 2024
@jonahgao
Copy link
Member Author

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant