-
Notifications
You must be signed in to change notification settings - Fork 29k
SPARK-1456 Remove view bounds on Ordered in favor of a context bound on Ordering. #410
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 1 commit
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 |
|---|---|---|
|
|
@@ -27,12 +27,14 @@ import org.apache.spark.{Logging, RangePartitioner} | |
| * use these functions. They will work with any key type that has a `scala.math.Ordered` | ||
| * implementation. | ||
| */ | ||
| class OrderedRDDFunctions[K <% Ordered[K]: ClassTag, | ||
| class OrderedRDDFunctions[K : Ordering : ClassTag, | ||
|
Contributor
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. @marmbrus Do you mind updating the scaladoc above since now users can pass their own orderings in addition to an
Contributor
Author
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. done. |
||
| V: ClassTag, | ||
| P <: Product2[K, V] : ClassTag]( | ||
| self: RDD[P]) | ||
| extends Logging with Serializable { | ||
|
|
||
| private val ordering = implicitly[Ordering[K]] | ||
|
|
||
| /** | ||
| * Sort the RDD by key, so that each partition contains a sorted range of the elements. Calling | ||
| * `collect` or `save` on the resulting RDD will return or output an ordered list of records | ||
|
|
@@ -45,9 +47,9 @@ class OrderedRDDFunctions[K <% Ordered[K]: ClassTag, | |
| shuffled.mapPartitions(iter => { | ||
| val buf = iter.toArray | ||
| if (ascending) { | ||
| buf.sortWith((x, y) => x._1 < y._1).iterator | ||
| buf.sortWith((x, y) => ordering.lt(x._1, y._1)).iterator | ||
| } else { | ||
| buf.sortWith((x, y) => x._1 > y._1).iterator | ||
| buf.sortWith((x, y) => ordering.gt(x._1, y._1)).iterator | ||
| } | ||
| }, preservesPartitioning = true) | ||
| } | ||
|
|
||
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.
Can the user still pass in an Ordering if they want a specific Ordering?
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.
Yes, when de-sugared there is an implicit Ordering -- that's why Michael can recover and bind it explicitly at line 98. And yes, it can be overridden in the normal way.