Skip to content

minor: Clean up shuffle transformation code in CometExecRule - #2840

Merged
andygrove merged 2 commits into
apache:mainfrom
andygrove:comet-exec-rule-refactor
Dec 3, 2025
Merged

andygrove merged 2 commits into
apache:mainfrom
andygrove:comet-exec-rule-refactor

Conversation

@andygrove

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

The shuffle transformation code that I previously implemented is not very easy to follow. This PR refactors it to be more readable and concise.

What changes are included in this PR?

How are these changes tested?

@codecov-commenter

codecov-commenter commented Dec 2, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.95238% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.16%. Comparing base (f09f8af) to head (960d9a0).
⚠️ Report is 731 commits behind head on main.

Files with missing lines Patch % Lines
...n/scala/org/apache/comet/rules/CometExecRule.scala 80.95% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2840      +/-   ##
============================================
+ Coverage     56.12%   59.16%   +3.04%     
- Complexity      976     1490     +514     
============================================
  Files           119      167      +48     
  Lines         11743    15272    +3529     
  Branches       2251     2523     +272     
============================================
+ Hits           6591     9036    +2445     
- Misses         4012     4945     +933     
- Partials       1140     1291     +151     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

}
// try native shuffle first, then columnar shuffle, then fall back to Spark
// if neither are supported
tryNativeShuffle(s).orElse(tryColumnarShuffle(s)).getOrElse(s)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is much easier to comprehend, IMO

@andygrove
andygrove marked this pull request as ready for review December 3, 2025 00:08

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @andygrove this is a nice clean up

Comment on lines -186 to -199
def operator2ProtoIfAllChildrenAreNative(op: SparkPlan): Option[Operator] = {
if (op.children.forall(_.isInstanceOf[CometNativeExec])) {
operator2Proto(op, op.children.map(_.asInstanceOf[CometNativeExec].nativeOp): _*)
} else {
None
}
}

/**
* Convert operator to proto and then apply a transformation to wrap the proto in a new plan.
*/
def newPlanWithProto(op: SparkPlan, fun: Operator => SparkPlan): SparkPlan = {
operator2ProtoIfAllChildrenAreNative(op).map(fun).getOrElse(op)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I moved these methods out of the transform method so that they can be accessed elsewhere

@mbutrovich mbutrovich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I love a negative line count! Thanks @andygrove

.flatMap(_ => operator2ProtoIfAllChildrenAreNative(s))
.map { nativeOp =>
// Switch to use Decimal128 regardless of precision, since Arrow native execution
// doesn't support Decimal32 and Decimal64 yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unrelated: I'm not sure if this is true anymore. I saw a lot of code related to Decimal32 and Decimal64 in DataFusion these days, so we might want to revisit this assumption from the early days of Comet.

@andygrove

Copy link
Copy Markdown
Member Author

Thanks for the reviews @comphead @mbutrovich

@andygrove
andygrove merged commit 9583d03 into apache:main Dec 3, 2025
126 of 127 checks passed
@andygrove
andygrove deleted the comet-exec-rule-refactor branch December 3, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants