Repository navigation
fix: ensure mutual compatibility of the two input schemas from recursive CTEs - #9795
Merged
Merged
Conversation
jonahgao
commented
Mar 25, 2024
| static_fields_len, recurive_fields_len | ||
| ); | ||
| } | ||
| // Ensure that the recursive term has the same field types as the static term |
Member
Author
There was a problem hiding this comment.
Not sure if it's necessary to ensure that the field names are the same.I tested some queries, and none of them failed.
The union operator uses project_with_column_index only ensures the field names of projection plans are the same.
DataFusion CLI v36.0.0
❯ -- The field names of the two input are the same.
explain select 1 union all select 2;
+--------------+------------------------------------+
| plan_type | plan |
+--------------+------------------------------------+
| logical_plan | Union |
| | Projection: Int64(1) AS Int64(1) |
| | EmptyRelation |
| | Projection: Int64(2) AS Int64(1) |
| | EmptyRelation |
+--------------+------------------------------------+
❯ -- The field names of the two input are different.
explain select 1 union all values(2);
+--------------+------------------------------------+
| plan_type | plan |
+--------------+------------------------------------+
| logical_plan | Union |
| | Projection: Int64(1) AS Int64(1) |
| | EmptyRelation |
| | Values: (Int64(2)) |
+--------------+------------------------------------+
Contributor
There was a problem hiding this comment.
Given the tests all pass this seems like a good plan to me.
alamb
approved these changes
Mar 27, 2024
| static_fields_len, recurive_fields_len | ||
| ); | ||
| } | ||
| // Ensure that the recursive term has the same field types as the static term |
Contributor
There was a problem hiding this comment.
Given the tests all pass this seems like a good plan to me.
Lordworms
pushed a commit
to Lordworms/arrow-datafusion
that referenced
this pull request
Apr 1, 2024
…ive CTEs (apache#9795) * fix: Ensure mutual compatibility of the two input schemas from recursive CTEs * fix typo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #9794.
Rationale for this change
Make the schema of the recursive term compatible with the static term.
This differs from the handling of the ordinary union operator. We can't change the static term's schema, otherwise we would have to recreate the logic plan of the recursive term, as it depends on the static term through the work table.
That is to say, we use the schema of the static term as the final schema for CTE.
DuckDB also adopted a similar approach.
D WITH RECURSIVE my_cte AS( SELECT 1::int AS a UNION ALL SELECT a::bigint+2 FROM my_cte WHERE a<3 ) SELECT a,typeof(a) FROM my_cte; ┌───────┬───────────┐ │ a │ typeof(a) │ │ int32 │ varchar │ ├───────┼───────────┤ │ 1 │ INTEGER │ │ 3 │ INTEGER │ └───────┴───────────┘The output type is
INTEGERfrom the static term, notBIGINT.What changes are included in this PR?
Check and coerce the schemas of recursive CTE's inputs.
Are these changes tested?
Yes
Are there any user-facing changes?
No