-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-18224] [CORE] Optimise PartitionedPairBuffer implementation #15736
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
Changes from all commits
0d1411c
a3d85b6
af4aea3
fc8f98e
d342394
53ed170
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,16 +75,22 @@ private[spark] object WritablePartitionedPairCollection { | |
| } | ||
|
|
||
| /** | ||
| * A comparator for (Int, K) pairs that orders them both by their partition ID and a key ordering. | ||
| * Takes an optional parameter (keyComparator), use if provided | ||
| * and returns a comparator for the partitions | ||
| */ | ||
| def partitionKeyComparator[K](keyComparator: Comparator[K]): Comparator[(Int, K)] = { | ||
| new Comparator[(Int, K)] { | ||
| override def compare(a: (Int, K), b: (Int, K)): Int = { | ||
| val partitionDiff = a._1 - b._1 | ||
| if (partitionDiff != 0) { | ||
| partitionDiff | ||
| } else { | ||
| keyComparator.compare(a._2, b._2) | ||
| def getComparator[K](keyComparator: Option[Comparator[K]]): Comparator[(Int, K)] = { | ||
| if (!keyComparator.isDefined) return partitionComparator | ||
| else { | ||
|
Member
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. Style is off here -- you need braces in both clauses, |
||
| val theKeyComp = keyComparator.get | ||
| new Comparator[(Int, K)] { | ||
| // We know we have a non-empty comparator here | ||
| override def compare(a: (Int, K), b: (Int, K)): Int = { | ||
| val partitionDiff = a._1 - b._1 | ||
| if (partitionDiff != 0) { | ||
|
Member
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. Probably very very slightly better to say |
||
| partitionDiff | ||
| } else { | ||
| theKeyComp.compare(a._2, b._2) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
inline and remove partitionComparator, as I think it's not used