-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Update optimize_children
to return Result<Option<LogicalPlan>>
#4888
Merged
alamb
merged 4 commits into
apache:master
from
HaoYang670:4882_optimize_children_return_option
Jan 14, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
} | ||
Comment on lines
42
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice👍 |
||
} | ||
|
||
/// Splits a conjunctive [`Expr`] such as `A AND B AND C` => `[A, B, C]` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to do this something like
Not sure if that is all that much better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, what is the rationale of this suggestion 🤔? It can't pass the type checker, I'm afraid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rationale was to make it slightly less verbose and more "functional" by using
map
rather thanmatch
. i don't think it is required