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

fix transforming LogicalPlan::Explain use TreeNode::transform fails #8400

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

haohuaijin
Copy link
Contributor

Which issue does this PR close?

Closes #8396

Rationale for this change

What changes are included in this PR?

make LogicalPlan::Explain can transform use TreeNode::transform

Are these changes tested?

yes, add one test

Are there any user-facing changes?

@github-actions github-actions bot added the logical-expr Logical plan and expressions label Dec 2, 2023
@@ -877,19 +877,20 @@ impl LogicalPlan {
input: Arc::new(inputs[0].clone()),
}))
}
LogicalPlan::Explain(_) => {
LogicalPlan::Explain(e) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I find we can correct transform LogicalPlan::Analyze in below
https://github.com/apache/arrow-datafusion/blob/340ecfdfe0e6667d2c9f528a60d8ee7fa5c34805/datafusion/expr/src/logical_plan/plan.rs#L871-L878
so I used the same approach in LogicalPlan::Explain

@haohuaijin
Copy link
Contributor Author

cc @trueleo , does this fix work for you?

@trueleo
Copy link

trueleo commented Dec 2, 2023

@haohuaijin Thank you so much for the fix. I'll test this out. (edit: This is working for the example code i presented in the issue)

I am still bit puzzled about the comment which was there.

// Explain should be handled specially in the optimizers;
// If this check cannot pass it means some optimizer pass is
// trying to optimize Explain directly 

Maybe @alamb can confirm that this change is not breaking anything else.

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.

Thank you @haohuaijin -- this makes sense to me and I think it is a nice fix 👏

@trueleo

I am still bit puzzled about the comment which was there.

// Explain should be handled specially in the optimizers;
// If this check cannot pass it means some optimizer pass is
// trying to optimize Explain directly 

Maybe @alamb can confirm that this change is not breaking anything else.

I think this comment is from a very long time ago when the optimizers were structured quite differently than they are today.

The change in this PR I think is correct and make sense to me

}

Ok(self.clone())
assert!(
Copy link
Contributor

@alamb alamb Dec 3, 2023

Choose a reason for hiding this comment

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

I recommend we make these checks return internal_err (so they error, rather than panic in case of bug), but this is consistent with the rest of the code in this file, so this is good

datafusion/expr/src/logical_plan/plan.rs Outdated Show resolved Hide resolved
@trueleo
Copy link

trueleo commented Dec 4, 2023

I think this comment is from a very long time ago when the optimizers were structured quite differently than they are today.

The change in this PR I think is correct and make sense to me

@alamb

I think i get the issue now. When running optimizer code there is matching on Explain so that the child plan of explain is optimized and output from the optimizations are then pushed to Explain's stringified_plans.

Thus transforming explain on it's own cannot make any changes to stringified_plans. It is left upto the caller to make the right decision.

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.

Thanks again @haohuaijin and @trueleo

@alamb alamb merged commit a73be00 into apache:main Dec 4, 2023
22 checks passed
@haohuaijin haohuaijin deleted the fix_explain branch December 4, 2023 11:59
appletreeisyellow pushed a commit to appletreeisyellow/datafusion that referenced this pull request Dec 15, 2023
…ls (apache#8400)

* fix transforming LogicalPlan::Explain use TreeNode::transform fails

* Update datafusion/expr/src/logical_plan/plan.rs

Co-authored-by: Andrew Lamb <[email protected]>

---------

Co-authored-by: Andrew Lamb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transforming LogicalPlan::Explain using Treenode::transform fails unexpectedly
3 participants