Skip to content

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

Closed

Description

@jonahgao

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

Activity

  1. jonahgao commented on Mar 25, 2024

    @jonahgao
    MemberAuthor

    take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions