diff options
author | seanm <sean.mcnamara@webtrends.com> | 2013-07-10 10:46:04 -0700 |
---|---|---|
committer | seanm <sean.mcnamara@webtrends.com> | 2013-07-10 10:46:04 -0700 |
commit | ee4ce2fc51112387f28d7b422969ca2e9736e95f (patch) | |
tree | 0c0e957da3a0958b2b1953d4af24aec1943cd5e1 /core/src/main | |
parent | 24705d0f46ce536bf829660f4506dcffd9ff799a (diff) | |
download | spark-ee4ce2fc51112387f28d7b422969ca2e9736e95f.tar.gz spark-ee4ce2fc51112387f28d7b422969ca2e9736e95f.tar.bz2 spark-ee4ce2fc51112387f28d7b422969ca2e9736e95f.zip |
adding takeOrdered to java API
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/scala/spark/api/java/JavaRDDLike.scala | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/core/src/main/scala/spark/api/java/JavaRDDLike.scala b/core/src/main/scala/spark/api/java/JavaRDDLike.scala index b555f2030a..94b95af714 100644 --- a/core/src/main/scala/spark/api/java/JavaRDDLike.scala +++ b/core/src/main/scala/spark/api/java/JavaRDDLike.scala @@ -384,4 +384,29 @@ trait JavaRDDLike[T, This <: JavaRDDLike[T, This]] extends Serializable { val comp = com.google.common.collect.Ordering.natural().asInstanceOf[Comparator[T]] top(num, comp) } + + /** + * Returns the top K elements from this RDD as defined by + * the specified Comparator[T] and maintains the order. + * @param num the number of top elements to return + * @param comp the comparator that defines the order + * @return an array of top elements + */ + def takeOrdered(num: Int, comp: Comparator[T]): JList[T] = { + import scala.collection.JavaConversions._ + val topElems = rdd.takeOrdered(num)(Ordering.comparatorToOrdering(comp)) + val arr: java.util.Collection[T] = topElems.toSeq + new java.util.ArrayList(arr) + } + + /** + * Returns the top K elements from this RDD using the + * natural ordering for T while maintain the order. + * @param num the number of top elements to return + * @return an array of top elements + */ + def takeOrdered(num: Int): JList[T] = { + val comp = com.google.common.collect.Ordering.natural().asInstanceOf[Comparator[T]] + takeOrdered(num, comp) + } } |