-
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 all commits
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 |
|---|---|---|
|
|
@@ -24,15 +24,31 @@ import org.apache.spark.{Logging, RangePartitioner} | |
| /** | ||
| * Extra functions available on RDDs of (key, value) pairs where the key is sortable through | ||
| * an implicit conversion. Import `org.apache.spark.SparkContext._` at the top of your program to | ||
| * use these functions. They will work with any key type that has a `scala.math.Ordered` | ||
| * implementation. | ||
| * use these functions. They will work with any key type `K` that has an implicit `Ordering[K]` in | ||
| * scope. Ordering objects already exist for all of the standard primitive types. Users can also | ||
| * define their own orderings for custom types, or to override the default ordering. The implicit | ||
| * ordering that is in the closest scope will be used. | ||
| * | ||
| * {{{ | ||
| * import org.apache.spark.SparkContext._ | ||
| * | ||
| * val rdd: RDD[(String, Int)] = ... | ||
| * implicit val caseInsensitiveOrdering = new Ordering[String] { | ||
| * override def compare(a: String, b: String) = a.toLowerCase.compare(b.toLowerCase) | ||
| * } | ||
| * | ||
| * // Sort by key, using the above case insensitive ordering. | ||
| * rdd.sortByKey() | ||
| * }}} | ||
| */ | ||
| 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 +61,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.