Skip to content
Snippets Groups Projects
Commit a2c915fb authored by seanm's avatar seanm
Browse files

giving order to top and making tests more clear

parent ee4ce2fc
No related branches found
No related tags found
No related merge requests found
......@@ -778,7 +778,7 @@ abstract class RDD[T: ClassManifest](
}.reduce { (queue1, queue2) =>
queue1 ++= queue2
queue1
}.toArray
}.toArray.sorted(ord.reverse)
}
/**
......@@ -789,9 +789,7 @@ abstract class RDD[T: ClassManifest](
* @param ord the implicit ordering for T
* @return an array of top elements
*/
def takeOrdered(num: Int)(implicit ord: Ordering[T]): Array[T] = {
top(num)(ord.reverse).sorted(ord)
}
def takeOrdered(num: Int)(implicit ord: Ordering[T]): Array[T] = top(num)(ord.reverse)
/**
* Save this RDD as a text file, using string representations of elements.
......
......@@ -240,7 +240,7 @@ class RDDSuite extends FunSuite with SharedSparkContext {
val ints = sc.makeRDD(scala.util.Random.shuffle(nums), 2)
val topK = ints.top(5)
assert(topK.size === 5)
assert(topK.sorted === nums.sorted.takeRight(5))
assert(topK === nums.reverse.take(5))
}
test("top with custom ordering") {
......@@ -255,9 +255,9 @@ class RDDSuite extends FunSuite with SharedSparkContext {
test("takeOrdered with predefined ordering") {
val nums = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val rdd = sc.makeRDD(nums, 2)
val sortedTopK = rdd.takeOrdered(5)
assert(sortedTopK.size === 5)
assert(sortedTopK === Array(1, 2, 3, 4, 5))
val sortedLowerK = rdd.takeOrdered(5)
assert(sortedLowerK.size === 5)
assert(sortedLowerK === Array(1, 2, 3, 4, 5))
}
test("takeOrdered with custom ordering") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment