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

Unparsing optimized (> 2 inputs) unions #14031

Merged
merged 10 commits into from
Jan 9, 2025
Merged

Conversation

MohamedAbdeen21
Copy link
Contributor

Which issue does this PR close?

Closes #13621.

Rationale for this change

Unparsing unions with more than 2 inputs (produced by the logical optimizer)

What changes are included in this PR?

Tests and required changes to unparser

Are these changes tested?

Yes

Are there any user-facing changes?

Should be able to unparse most unions

@github-actions github-actions bot added the sql SQL Planner label Jan 6, 2025
@MohamedAbdeen21
Copy link
Contributor Author

Looks like there's a circular dep between optimizer and SQL packages. The easiest solution is moving the test somewhere else, not sure where though

@goldmedal
Copy link
Contributor

Thanks for working on this, @MohamedAbdeen21
Instead of applying optimization rules when roundtrip tests, I prefer to construct the expected plan manually. Just like other test cases like

fn test_join_with_table_scan_filters() -> Result<()> {

If we add the optimization to the testing, the optimizer's behavior will be limited by the unparser but we don't expect it. (see the previous discussion #13267 (comment))

@MohamedAbdeen21
Copy link
Contributor Author

Thanks for the suggestion @goldmedal, updated accordingly

Copy link
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MohamedAbdeen21. Overall looks good to me. Just some minor comments.
cc @phillipleblanc

datafusion/sql/src/unparser/plan.rs Show resolved Hide resolved
datafusion/sql/src/unparser/plan.rs Show resolved Hide resolved
Copy link
Contributor

@phillipleblanc phillipleblanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this @MohamedAbdeen21!

@MohamedAbdeen21
Copy link
Contributor Author

@goldmedal reverted let Some(..) .. else so we can correctly error on union w/ 1 input.

@goldmedal goldmedal merged commit 5955860 into apache:main Jan 9, 2025
25 checks passed
@goldmedal
Copy link
Contributor

Thanks @MohamedAbdeen21 and @phillipleblanc for the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unparse UNION plan with multiple inputs to SQL text
3 participants