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

[SPARK-50683][SQL] Inline the common expression in With if used once #49310

Closed
wants to merge 1 commit into from

Conversation

zml1206
Copy link
Contributor

@zml1206 zml1206 commented Dec 27, 2024

What changes were proposed in this pull request?

As title.

Why are the changes needed?

Simplify plan and reduce unnecessary project.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

UT.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label Dec 27, 2024
@zml1206
Copy link
Contributor Author

zml1206 commented Dec 27, 2024

cc @cloud-fan Thank you.

@zml1206
Copy link
Contributor Author

zml1206 commented Dec 27, 2024

CI failure is not relevant.

@@ -68,9 +68,15 @@ object RewriteWithExpression extends Rule[LogicalPlan] {

private def applyInternal(p: LogicalPlan): LogicalPlan = {
val inputPlans = p.children
val commonExprIdSet = p.expressions
.flatMap(_.collect { case r: CommonExpressionRef => r.id })
Copy link
Contributor

Choose a reason for hiding this comment

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

We should avoid collecting references from nested With, as this rule skips nested With and leaves it to the next iteration.

Copy link
Contributor Author

@zml1206 zml1206 Dec 27, 2024

Choose a reason for hiding this comment

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

I think collecting references from nested With is necessary, e.g. With(ref0 + With(ref1 + ref1, Seq(def(ref0+b,1))), Seq(def(a+a,0))), first iteration will replace all ref0.
This will collect additional ref1, but it will not affect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ping gently @cloud-fan

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see, makes sense

@zml1206 zml1206 requested a review from cloud-fan December 30, 2024 07:55
@cloud-fan
Copy link
Contributor

The Spark Connect test failure is unrelated, thanks, merging to master!

@cloud-fan cloud-fan closed this in 492fcd8 Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants