You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "phillipleblanc (via GitHub)" <gi...@apache.org> on 2024/05/21 15:41:11 UTC

[PR] Implement Unparser for `UNION ALL` [datafusion]

phillipleblanc opened a new pull request, #10603:
URL: https://github.com/apache/datafusion/pull/10603

   ## Which issue does this PR close?
   
   It doesn't close this issue, but is part of the work for #9494
   
   ## Rationale for this change
   
   Adds support for turning LogicalPlans that have `Union` LogicalPlans (without distinct, so only `UNION ALL`, not `UNION`) into SQL strings.
   
   ## What changes are included in this PR?
   
   Splits `select_to_sql` into two parts: `select_to_sql_statement` and `select_to_sql_expr`. LIMIT and ORDER BY are only valid in a statement context, whereas all other plans can appear in a SELECT expression. This allows the parsing for UNION ALL to turn each of its inputs into a SELECT expression, and still respect the LIMIT/ORDER BY at the statement level.
   
   ## Are these changes tested?
   
   Yes, added two tests to the `roundtrip_sql` integration test.
   
   ## Are there any user-facing changes?
   
   This expands the valid plans that can be unparsed back to SQL strings, and is backwards compatible.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement Unparser for `UNION ALL` [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #10603:
URL: https://github.com/apache/datafusion/pull/10603#discussion_r1608860177


##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -347,8 +373,33 @@ impl Unparser<'_> {
 
                 Ok(())
             }
-            LogicalPlan::Union(_union) => {
-                not_impl_err!("Unsupported operator: {plan:?}")
+            LogicalPlan::Union(union) => {

Review Comment:
   I double checked that Union is UNION ALL https://docs.rs/datafusion/latest/datafusion/logical_expr/struct.Union.html



##########
datafusion/sql/tests/sql_integration.rs:
##########
@@ -4641,6 +4641,14 @@ fn roundtrip_statement() -> Result<()> {
             group by "Last Name", p.id 
             having count_first_name>5 and count_first_name<10
             order by count_first_name, "Last Name""#,
+            r#"SELECT j1_string as string FROM j1

Review Comment:
   Perhaps we should also add a test (as a follow on PR) for `UNION` (not `UNION ALL`) 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Implement Unparser for `UNION ALL` [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #10603:
URL: https://github.com/apache/datafusion/pull/10603


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org