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

Fix to unparse the plan with multiple UNION statements into an SQL string #12605

Merged
merged 3 commits into from
Sep 25, 2024

Conversation

goldmedal
Copy link
Contributor

Which issue does this PR close?

No corrsponding issue.

Rationale for this change

Consider the following SQL:

WITH 
    w1 AS (SELECT 'a' as col),
    w2 AS (SELECT 'b' as col),
    w3 as (SELECT 'c' as col)
SELECT * FROM w1 UNION ALL SELECT * FROM w2 UNION ALL SELECT * FROM w3

If a plan contains more than two UNION statements, it cannot be properly unparsed back into an SQL string.

What changes are included in this PR?

Fix the unparsing behavior for UNION.

Are these changes tested?

yes

Are there any user-facing changes?

no

@github-actions github-actions bot added the sql SQL Planner label Sep 24, 2024
@goldmedal goldmedal changed the title Fix to unparse the plan with multiple UNION statements into an SQL string. Fix to unparse the plan with multiple UNION statements into an SQL string Sep 24, 2024
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 @goldmedal! One minor comment on the error message, but otherwise looks good to me! I should have tested more than 2 UNIONs initially 😅

datafusion/sql/src/unparser/plan.rs Outdated Show resolved Hide resolved
goldmedal and others added 2 commits September 25, 2024 09:56
Co-authored-by: Phillip LeBlanc <phillip@leblanc.tech>
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks good to me -- thank you @goldmedal and @phillipleblanc for the review

@alamb alamb merged commit 65595cf into apache:main Sep 25, 2024
24 checks passed
@goldmedal goldmedal deleted the bugfix/fix-unparse-union branch September 25, 2024 11:23
@goldmedal
Copy link
Contributor Author

Thanks @alamb @phillipleblanc !

bgjackma pushed a commit to bgjackma/datafusion that referenced this pull request Sep 25, 2024
…ring (apache#12605)

* fix unparse multiple UNION statement

* enhance the error message

Co-authored-by: Phillip LeBlanc <phillip@leblanc.tech>

* cargo fmt

---------

Co-authored-by: Phillip LeBlanc <phillip@leblanc.tech>
sgrebnov pushed a commit to spiceai/datafusion that referenced this pull request Oct 1, 2024
…ring (apache#12605)

* fix unparse multiple UNION statement

* enhance the error message

Co-authored-by: Phillip LeBlanc <phillip@leblanc.tech>

* cargo fmt

---------

Co-authored-by: Phillip LeBlanc <phillip@leblanc.tech>
sgrebnov added a commit to spiceai/datafusion that referenced this pull request Oct 1, 2024
…ring (apache#12605) (#37)

* fix unparse multiple UNION statement

* enhance the error message



* cargo fmt

---------

Co-authored-by: Jax Liu <liugs963@gmail.com>
Co-authored-by: Phillip LeBlanc <phillip@leblanc.tech>
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.

3 participants