Skip to content
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
merged 4 commits into from
Jan 14, 2023

Conversation

HaoYang670
Copy link
Contributor

Which issue does this PR close?

Closes #4882.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

Signed-off-by: remzi <13716567376yh@gmail.com>
Signed-off-by: remzi <13716567376yh@gmail.com>
@github-actions github-actions bot added core Core DataFusion crate optimizer Optimizer rules labels Jan 13, 2023
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- thank you. @HaoYang670 for the contribution. cc @jackwener

Comment on lines +248 to +256
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),
Copy link
Contributor

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

Suggested change
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),
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

Copy link
Contributor Author

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.

Copy link
Contributor

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 than match. i don't think it is required

Copy link
Member

@jackwener jackwener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job

Comment on lines 42 to +59
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)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice👍

@@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
utils::optimize_children(self, &new_plan, config)?.unwrap_or(new_plan),
optimize_children(self, &new_plan, config)?.unwrap_or(new_plan),

@HaoYang670
Copy link
Contributor Author

Thanks for your review @alamb @jackwener 😁
Please don't merge this now. I'll address your feedbacks this evening or tomorrow.

@alamb
Copy link
Contributor

alamb commented Jan 14, 2023

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

@alamb alamb marked this pull request as draft January 14, 2023 11:33
Signed-off-by: remzi <13716567376yh@gmail.com>
@HaoYang670 HaoYang670 marked this pull request as ready for review January 14, 2023 12:53
@alamb
Copy link
Contributor

alamb commented Jan 14, 2023

LGTM -- thanks again @HaoYang670

@alamb alamb merged commit d37dccf into apache:master Jan 14, 2023
@ursabot
Copy link

ursabot commented Jan 14, 2023

Benchmark runs are scheduled for baseline = 42c81be and contender = d37dccf. d37dccf is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
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

@HaoYang670 HaoYang670 deleted the 4882_optimize_children_return_option branch January 15, 2023 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate optimizer Optimizer rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the type of optimize_children to return Result<Option<LogicalPlan>>
4 participants