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 2023/01/13 07:23:27 UTC
[GitHub] [arrow-datafusion] HaoYang670 opened a new pull request, #4888: Update `optimize_children` to return `Result
HaoYang670 opened a new pull request, #4888:
URL: https://github.com/apache/arrow-datafusion/pull/4888
# 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 #4882.
# 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.
-->
# 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?
<!--
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?
<!--
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] HaoYang670 commented on pull request #4888: Update `optimize_children` to return `Result
Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on PR #4888:
URL: https://github.com/apache/arrow-datafusion/pull/4888#issuecomment-1382589422
Thanks for your review @alamb @jackwener π
Please don't merge this now. I'll address your feedbacks this evening or tomorrow.
--
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 #4888: Update `optimize_children` to return `Result
Posted by GitBox <gi...@apache.org>.
jackwener commented on code in PR #4888:
URL: https://github.com/apache/arrow-datafusion/pull/4888#discussion_r1069161553
##########
datafusion/optimizer/src/push_down_filter.rs:
##########
@@ -749,7 +749,9 @@ impl OptimizerRule for PushDownFilter {
_ => plan.clone(),
};
- Ok(Some(utils::optimize_children(self, &new_plan, config)?))
+ Ok(Some(
+ utils::optimize_children(self, &new_plan, config)?.unwrap_or(new_plan),
Review Comment:
```suggestion
optimize_children(self, &new_plan, config)?.unwrap_or(new_plan),
```
##########
datafusion/optimizer/src/utils.rs:
##########
@@ -37,18 +37,26 @@ use std::sync::Arc;
/// type. Useful for optimizer rules which want to leave the type
/// of plan unchanged but still apply to the children.
/// This also handles the case when the `plan` is a [`LogicalPlan::Explain`].
+///
+/// Returning `Ok(None)` indicates that the plan can't be optimized by the `optimizer`.
pub fn optimize_children(
optimizer: &impl OptimizerRule,
plan: &LogicalPlan,
config: &dyn OptimizerConfig,
-) -> Result<LogicalPlan> {
+) -> Result<Option<LogicalPlan>> {
let new_exprs = plan.expressions();
let mut new_inputs = Vec::with_capacity(plan.inputs().len());
+ let mut plan_is_changed = false;
for input in plan.inputs() {
let new_input = optimizer.try_optimize(input, config)?;
+ plan_is_changed = plan_is_changed || new_input.is_some();
new_inputs.push(new_input.unwrap_or_else(|| input.clone()))
}
- from_plan(plan, &new_exprs, &new_inputs)
+ if plan_is_changed {
+ Ok(Some(from_plan(plan, &new_exprs, &new_inputs)?))
+ } else {
+ Ok(None)
+ }
Review Comment:
Niceπ
--
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
alamb merged PR #4888:
URL: https://github.com/apache/arrow-datafusion/pull/4888
--
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 #4888: Update `optimize_children` to return `Result
Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #4888:
URL: https://github.com/apache/arrow-datafusion/pull/4888#issuecomment-1382865359
Benchmark runs are scheduled for baseline = 42c81be3e1ebd41d55108558afc9fb8e6de988ee and contender = d37dccf6d825762ba5d25a7ac1d10a1f0756e0a6. d37dccf6d825762ba5d25a7ac1d10a1f0756e0a6 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/ba9608d792634206866ceb943184bbaf...ef82c0ad073d4a908fb7abbde2d7e52f/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/9ef0844acbd442049d3835897daaecd3...efeb7368503243d5b39ddb4116d40bc2/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/b9fc559fc41b4c7690277a0dd535a2e6...89a4a8297efd4f90a23361cd49802764/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/e3d6e6e10d0a41fab9486db507886b24...61c3f8188b374ae4a40ee4b782d34268/)
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 commented on a diff in pull request #4888: Update `optimize_children` to return `Result
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4888:
URL: https://github.com/apache/arrow-datafusion/pull/4888#discussion_r1069120955
##########
datafusion/optimizer/src/common_subexpr_eliminate.rs:
##########
@@ -242,12 +245,16 @@ impl OptimizerRule for CommonSubexprEliminate {
}
};
- // add an additional projection if the output schema changed.
- if optimized_plan.schema() != &original_schema {
- optimized_plan = build_recover_project_plan(&original_schema, optimized_plan);
+ match optimized_plan {
+ Some(optimized_plan) if optimized_plan.schema() != &original_schema => {
+ // add an additional projection if the output schema changed.
+ Ok(Some(build_recover_project_plan(
+ &original_schema,
+ optimized_plan,
+ )))
+ }
+ plan => Ok(plan),
Review Comment:
You might be able to do this something like
```suggestion
optimized_plan.map(|optimized_plan| {
if optimized_plan.schema() != &original_schema => {
// add an additional projection if the output schema changed.
build_recover_project_plan(
&original_schema,
optimized_plan,
)
});
```
Not sure if that is all that much better
--
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 #4888: Update `optimize_children` to return `Result
Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4888:
URL: https://github.com/apache/arrow-datafusion/pull/4888#discussion_r1070350280
##########
datafusion/optimizer/src/common_subexpr_eliminate.rs:
##########
@@ -242,12 +245,16 @@ impl OptimizerRule for CommonSubexprEliminate {
}
};
- // add an additional projection if the output schema changed.
- if optimized_plan.schema() != &original_schema {
- optimized_plan = build_recover_project_plan(&original_schema, optimized_plan);
+ match optimized_plan {
+ Some(optimized_plan) if optimized_plan.schema() != &original_schema => {
+ // add an additional projection if the output schema changed.
+ Ok(Some(build_recover_project_plan(
+ &original_schema,
+ optimized_plan,
+ )))
+ }
+ plan => Ok(plan),
Review Comment:
The rationale was to make it slightly less verbose and more "functional" by using `map` rather than `match`. i don't think it is required
--
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 #4888: Update `optimize_children` to return `Result
Posted by GitBox <gi...@apache.org>.
alamb commented on PR #4888:
URL: https://github.com/apache/arrow-datafusion/pull/4888#issuecomment-1382862732
LGTM -- thanks again @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] HaoYang670 commented on a diff in pull request #4888: Update `optimize_children` to return `Result
Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #4888:
URL: https://github.com/apache/arrow-datafusion/pull/4888#discussion_r1070261544
##########
datafusion/optimizer/src/common_subexpr_eliminate.rs:
##########
@@ -242,12 +245,16 @@ impl OptimizerRule for CommonSubexprEliminate {
}
};
- // add an additional projection if the output schema changed.
- if optimized_plan.schema() != &original_schema {
- optimized_plan = build_recover_project_plan(&original_schema, optimized_plan);
+ match optimized_plan {
+ Some(optimized_plan) if optimized_plan.schema() != &original_schema => {
+ // add an additional projection if the output schema changed.
+ Ok(Some(build_recover_project_plan(
+ &original_schema,
+ optimized_plan,
+ )))
+ }
+ plan => Ok(plan),
Review Comment:
Hmm, what is the rationale of this suggestion π€? It can't pass the type checker, I'm afraid.
--
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 #4888: Update `optimize_children` to return `Result
Posted by GitBox <gi...@apache.org>.
alamb commented on PR #4888:
URL: https://github.com/apache/arrow-datafusion/pull/4888#issuecomment-1382718625
> Please don't merge this now. I'll address your feedbacks this evening or tomorrow.
π thank you @HaoYang670 -- I'll mark this PR as a draft so we don't accidentally merge it while working through the backlog
--
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