You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "blaginin (via GitHub)" <gi...@apache.org> on 2025/03/11 13:58:01 UTC
[PR] Only unnest source for `EmptyRelation` [datafusion]
blaginin opened a new pull request, #15159:
URL: https://github.com/apache/datafusion/pull/15159
## Which issue does this PR close?
Closes https://github.com/apache/datafusion/issues/15128
## Rationale for this change
We currently override source losing some data, see issue for examples
## What changes are included in this PR?
## Are these changes tested?
Added tests
## Are there any user-facing changes?
No
--
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] Only unnest source for `EmptyRelation` [datafusion]
Posted by "goldmedal (via GitHub)" <gi...@apache.org>.
goldmedal merged PR #15159:
URL: https://github.com/apache/datafusion/pull/15159
--
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] Only unnest source for `EmptyRelation` [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #15159:
URL: https://github.com/apache/datafusion/pull/15159#discussion_r1997328648
##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -377,8 +377,17 @@ impl Unparser<'_> {
};
if self.dialect.unnest_as_table_factor() && unnest_input_type.is_some() {
if let LogicalPlan::Unnest(unnest) = &p.input.as_ref() {
- return self
- .unnest_to_table_factor_sql(unnest, query, select, relation);
+ if let LogicalPlan::Projection(projection) = unnest.input.as_ref()
+ {
+ if matches!(
+ projection.input.as_ref(),
+ LogicalPlan::EmptyRelation(_)
Review Comment:
Thank you, added in https://github.com/apache/datafusion/pull/15159/commits/28f53014482399c6f74ac2bfda464de712705663
--
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] Only unnest source for `EmptyRelation` [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #15159:
URL: https://github.com/apache/datafusion/pull/15159#discussion_r2007638250
##########
datafusion/sql/tests/cases/plan_to_sql.rs:
##########
Review Comment:
Sorry -- before I added one more test, but then I have to remove it due to (https://github.com/apache/datafusion/pull/15159/commits/ef4a79dd160c452f8f92c82ac151131865c2e965) - I think we can discuss in that issue and work on it further
##########
datafusion/sql/tests/cases/plan_to_sql.rs:
##########
Review Comment:
Sorry -- before I added one more test, but then I have to remove it due to https://github.com/apache/datafusion/pull/15159/commits/ef4a79dd160c452f8f92c82ac151131865c2e965 - I think we can discuss in that issue and work on it further
--
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] Only unnest source for `EmptyRelation` [datafusion]
Posted by "goldmedal (via GitHub)" <gi...@apache.org>.
goldmedal commented on code in PR #15159:
URL: https://github.com/apache/datafusion/pull/15159#discussion_r2008701304
##########
datafusion/sql/tests/cases/plan_to_sql.rs:
##########
@@ -633,6 +633,18 @@ fn roundtrip_statement_with_dialect() -> Result<()> {
parser_dialect: Box::new(GenericDialect {}),
unparser_dialect: Box::new(CustomDialectBuilder::default().with_unnest_as_table_factor(true).build()),
},
+ TestStatementWithDialect {
+ sql: "SELECT unnest([1, 2, 3, 4]) from unnest([1, 2, 3]);",
+ expected: r#"SELECT UNNEST([1, 2, 3, 4]) AS UNNEST(make_array(Int64(1),Int64(2),Int64(3),Int64(4))) FROM UNNEST([1, 2, 3])"#,
+ parser_dialect: Box::new(GenericDialect {}),
+ unparser_dialect: Box::new(CustomDialectBuilder::default().with_unnest_as_table_factor(true).build()),
+ },
+ TestStatementWithDialect {
+ sql: "SELECT unnest([1, 2, 3, 4]) from unnest([1, 2, 3]);",
+ expected: r#"SELECT UNNEST([1, 2, 3, 4]) AS UNNEST(make_array(Int64(1),Int64(2),Int64(3),Int64(4))) FROM UNNEST([1, 2, 3])"#,
+ parser_dialect: Box::new(GenericDialect {}),
+ unparser_dialect: Box::new(CustomDialectBuilder::default().with_unnest_as_table_factor(true).build()),
+ },
Review Comment:
They look like the same. 🤔 I think we can remove one of them.
--
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] Only unnest source for `EmptyRelation` [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #15159:
URL: https://github.com/apache/datafusion/pull/15159#discussion_r1998600989
##########
datafusion/sql/tests/cases/plan_to_sql.rs:
##########
Review Comment:
Had to remove this _new_ test because now (even in main) it produces `SELECT * FROM (SELECT [1, 2, 3] AS c) CROSS JOIN UNNEST(c)`. Feels like this should be discussed separately
--
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] Only unnest source for `EmptyRelation` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15159:
URL: https://github.com/apache/datafusion/pull/15159#issuecomment-2737960183
Marking as draft as I think this PR is no longer waiting on feedback. Please mark it as ready for review when it is ready for another look
--
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] Only unnest source for `EmptyRelation` [datafusion]
Posted by "goldmedal (via GitHub)" <gi...@apache.org>.
goldmedal commented on PR #15159:
URL: https://github.com/apache/datafusion/pull/15159#issuecomment-2747772795
Thanks @blaginin and @alamb for reviewing. I'll create a follow-up PR to remove the duplicate test.
--
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] Only unnest source for `EmptyRelation` [datafusion]
Posted by "blaginin (via GitHub)" <gi...@apache.org>.
blaginin commented on code in PR #15159:
URL: https://github.com/apache/datafusion/pull/15159#discussion_r1998600989
##########
datafusion/sql/tests/cases/plan_to_sql.rs:
##########
Review Comment:
Had to remove this because now (even in main) it produces `SELECT * FROM (SELECT [1, 2, 3] AS c) CROSS JOIN UNNEST(c)`. Feels like this should be discussed separately
--
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] Only unnest source for `EmptyRelation` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #15159:
URL: https://github.com/apache/datafusion/pull/15159#discussion_r1999670066
##########
datafusion/sql/tests/cases/plan_to_sql.rs:
##########
Review Comment:
I don't understand this comment -- doesn't this PR *add* a new test?
##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -377,8 +377,23 @@ impl Unparser<'_> {
};
if self.dialect.unnest_as_table_factor() && unnest_input_type.is_some() {
if let LogicalPlan::Unnest(unnest) = &p.input.as_ref() {
- return self
- .unnest_to_table_factor_sql(unnest, query, select, relation);
+ if let LogicalPlan::Projection(projection) = unnest.input.as_ref()
Review Comment:
This feels like something that is a limitation of `unnest_to_table_factor_sql` -- would it make sense to put the check in there so the check and the code with the assumption are in the same place?
--
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] Only unnest source for `EmptyRelation` [datafusion]
Posted by "goldmedal (via GitHub)" <gi...@apache.org>.
goldmedal commented on code in PR #15159:
URL: https://github.com/apache/datafusion/pull/15159#discussion_r1991567742
##########
datafusion/sql/src/unparser/plan.rs:
##########
@@ -377,8 +377,17 @@ impl Unparser<'_> {
};
if self.dialect.unnest_as_table_factor() && unnest_input_type.is_some() {
if let LogicalPlan::Unnest(unnest) = &p.input.as_ref() {
- return self
- .unnest_to_table_factor_sql(unnest, query, select, relation);
+ if let LogicalPlan::Projection(projection) = unnest.input.as_ref()
+ {
+ if matches!(
+ projection.input.as_ref(),
+ LogicalPlan::EmptyRelation(_)
Review Comment:
It's better to add some comments to explain why we match `EmptyRelation`.
--
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