You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/28 06:02:26 UTC
[GitHub] [arrow-datafusion] HaoYang670 opened a new pull request, #4753: Take the top level `schema` into account when creating `UnionExec`
HaoYang670 opened a new pull request, #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753
Signed-off-by: remzi <13...@gmail.com>
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #4677.
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
When creating `UnionExec` from `LogicalPlan::Union`, the schema of the top plan is ignored. This could cause errors when the top level schema doesn't match the child schema. (see the example in #4677)
## Before
```sql
❯ create table t as select 1 as a;
0 rows in set. Query took 0.014 seconds.
❯ select count(*) from (select a from t union all select a from t);
Internal("create_physical_expr expected same number of fields, got got Arrow schema with 1 and DataFusion schema with 0")
```
## After
```sql
❯ create table t as select 1 as a;
0 rows in set. Query took 0.014 seconds.
❯ select count(*) from (select a from t union all select a from t);
+-----------------+
| COUNT(UInt8(1)) |
+-----------------+
| 2 |
+-----------------+
1 row in set. Query took 0.010 seconds.
```
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
# Are these changes tested?
Yes.
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
# Are there any user-facing changes?
No.
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] ursabot commented on pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#issuecomment-1368034616
Benchmark runs are scheduled for baseline = cf45eb9020092943b96653d70fafb143cc362e19 and contender = 5b125b1fe19c6d105d22eab3adf68f8ed75eb630. 5b125b1fe19c6d105d22eab3adf68f8ed75eb630 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/6849de8072134216aba9ff27c158483a...d7fa7ff9ac644bb1afc4e0eb46f42438/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/7d4593aee8b8421faa7f606614c86462...f3025656b2e142d38687bfe013ec5d78/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/7d0a60ab37344f588d213ba6db48bad3...66f90c15e179497fb580f836b356c969/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/44e46965cd8f45539909ff978811bf9d...2ee8d70523b2400f861d17068ba04d8f/)
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb merged pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
alamb merged PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#discussion_r1058590886
##########
datafusion/core/tests/sql/union.rs:
##########
@@ -80,6 +80,23 @@ async fn union_all_with_aggregate() -> Result<()> {
Ok(())
}
+#[tokio::test]
+async fn union_all_with_count() -> Result<()> {
+ let ctx = SessionContext::new();
+ execute_to_batches(&ctx, "CREATE table t as SELECT 1 as a").await;
+ let sql = "SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a from t)";
Review Comment:
👍 agrees with postgres:
```sql
postgres=# CREATE table t as SELECT 1 as a;
SELECT 1
postgres=# SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a from t);
ERROR: subquery in FROM must have an alias
LINE 1: SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a fro...
^
HINT: For example, FROM (SELECT ...) [AS] foo.
postgres=# SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a from t) as sq;
count
-------
2
(1 row)
```
##########
datafusion/core/src/physical_plan/planner.rs:
##########
@@ -773,12 +773,19 @@ impl DefaultPhysicalPlanner {
)?;
Ok(Arc::new(FilterExec::try_new(runtime_expr, physical_input)?))
}
- LogicalPlan::Union(Union { inputs, .. }) => {
+ LogicalPlan::Union(Union { inputs, schema }) => {
let physical_plans = futures::stream::iter(inputs)
.then(|lp| self.create_initial_plan(lp, session_state))
.try_collect::<Vec<_>>()
.await?;
- Ok(Arc::new(UnionExec::new(physical_plans)))
+ if schema.fields().len() < physical_plans[0].schema().fields().len() {
Review Comment:
I wonder what is the reason to not always run `UnionExec::try_new_with_schema`?
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
jackwener commented on code in PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#discussion_r1059230136
##########
datafusion/core/tests/sql/union.rs:
##########
@@ -80,6 +80,23 @@ async fn union_all_with_aggregate() -> Result<()> {
Ok(())
}
+#[tokio::test]
+async fn union_all_with_count() -> Result<()> {
+ let ctx = SessionContext::new();
+ execute_to_batches(&ctx, "CREATE table t as SELECT 1 as a").await;
+ let sql = "SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a from t)";
Review Comment:
> BTW, I'm not sure if it was a bug, but the `PushDownProjection` doesn't push down the empty projection to the child plans of `Union` in this example. Maybe @jackwener knows more about it.
we need an issue to track this problem, I think there are some different ways of dealing with this problem.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] HaoYang670 commented on a diff in pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#discussion_r1059232377
##########
datafusion/core/tests/sql/union.rs:
##########
@@ -80,6 +80,23 @@ async fn union_all_with_aggregate() -> Result<()> {
Ok(())
}
+#[tokio::test]
+async fn union_all_with_count() -> Result<()> {
+ let ctx = SessionContext::new();
+ execute_to_batches(&ctx, "CREATE table t as SELECT 1 as a").await;
+ let sql = "SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a from t)";
Review Comment:
Could you please file an issue @jackwener ?
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] HaoYang670 commented on a diff in pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#discussion_r1059232866
##########
datafusion/core/src/physical_plan/planner.rs:
##########
@@ -773,12 +773,19 @@ impl DefaultPhysicalPlanner {
)?;
Ok(Arc::new(FilterExec::try_new(runtime_expr, physical_input)?))
}
- LogicalPlan::Union(Union { inputs, .. }) => {
+ LogicalPlan::Union(Union { inputs, schema }) => {
let physical_plans = futures::stream::iter(inputs)
.then(|lp| self.create_initial_plan(lp, session_state))
.try_collect::<Vec<_>>()
.await?;
- Ok(Arc::new(UnionExec::new(physical_plans)))
+ if schema.fields().len() < physical_plans[0].schema().fields().len() {
Review Comment:
Hmm, after double thinking, I am uncertain whether it is correct to ignore the top level schema when generating physical plans. It would lose the information about type coercion and metadata.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] HaoYang670 commented on pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#issuecomment-1368127160
> A great job to me.
>
> But I am a little confusing about this PR. Why we can't correct the LogicalPlan but fix them in PhysicalPlan? Current problem is cause by `schema`, maybe we fix `schema` in LogicalPlan?
We could revert this PR if the bug in logical optimizer could be solved. This PR is just a quick fix.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
alamb commented on PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#issuecomment-1368031702
I feel like this PR is good enough to merge in the sense that a query that used to fail now runs correctly and there is additional test coverage. It sounds like there are likely more improvements possible as well
Thanks for the comments and review @jackwener and @HaoYang670
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#discussion_r1058932971
##########
datafusion/core/src/physical_plan/planner.rs:
##########
@@ -773,12 +773,19 @@ impl DefaultPhysicalPlanner {
)?;
Ok(Arc::new(FilterExec::try_new(runtime_expr, physical_input)?))
}
- LogicalPlan::Union(Union { inputs, .. }) => {
+ LogicalPlan::Union(Union { inputs, schema }) => {
let physical_plans = futures::stream::iter(inputs)
.then(|lp| self.create_initial_plan(lp, session_state))
.try_collect::<Vec<_>>()
.await?;
- Ok(Arc::new(UnionExec::new(physical_plans)))
+ if schema.fields().len() < physical_plans[0].schema().fields().len() {
Review Comment:
Sounds good -- maybe I'll try to simply the code once we have merged this PR
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] HaoYang670 commented on a diff in pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#discussion_r1058694733
##########
datafusion/core/src/physical_plan/planner.rs:
##########
@@ -773,12 +773,19 @@ impl DefaultPhysicalPlanner {
)?;
Ok(Arc::new(FilterExec::try_new(runtime_expr, physical_input)?))
}
- LogicalPlan::Union(Union { inputs, .. }) => {
+ LogicalPlan::Union(Union { inputs, schema }) => {
let physical_plans = futures::stream::iter(inputs)
.then(|lp| self.create_initial_plan(lp, session_state))
.try_collect::<Vec<_>>()
.await?;
- Ok(Arc::new(UnionExec::new(physical_plans)))
+ if schema.fields().len() < physical_plans[0].schema().fields().len() {
Review Comment:
The original implementation ignores the top level schema, but I don't know why. (Maybe @gandronchik knows more about it). So I try to minimize the scope of this change to avoid introducing new bugs.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] HaoYang670 commented on a diff in pull request #4753: Take the top level `schema` into account when creating `UnionExec`
Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#discussion_r1058696036
##########
datafusion/core/tests/sql/union.rs:
##########
@@ -80,6 +80,23 @@ async fn union_all_with_aggregate() -> Result<()> {
Ok(())
}
+#[tokio::test]
+async fn union_all_with_count() -> Result<()> {
+ let ctx = SessionContext::new();
+ execute_to_batches(&ctx, "CREATE table t as SELECT 1 as a").await;
+ let sql = "SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a from t)";
Review Comment:
BTW, I'm not sure if it was a bug, but the `PushDownProjection` doesn't push down the empty projection to the child plans of `Union` in this example. Maybe @jackwener knows more about it.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org