From 492a195c5c4d68c85b8b1b48e3aa85165bbb5dc3 Mon Sep 17 00:00:00 2001
From: Rui Li <rui.li@intel.com>
Date: Thu, 31 Jul 2014 15:07:26 -0700
Subject: [PATCH] SPARK-2740: allow user to specify ascending and numPartitions
 for sortBy...

It should be more convenient if user can specify ascending and numPartitions when calling sortByKey.

Author: Rui Li <rui.li@intel.com>

Closes #1645 from lirui-intel/spark-2740 and squashes the following commits:

fb5d52e [Rui Li] SPARK-2740: allow user to specify ascending and numPartitions for sortByKey
---
 .../scala/org/apache/spark/api/java/JavaPairRDD.scala | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/core/src/main/scala/org/apache/spark/api/java/JavaPairRDD.scala b/core/src/main/scala/org/apache/spark/api/java/JavaPairRDD.scala
index 47708cb2e7..76d4193e96 100644
--- a/core/src/main/scala/org/apache/spark/api/java/JavaPairRDD.scala
+++ b/core/src/main/scala/org/apache/spark/api/java/JavaPairRDD.scala
@@ -783,6 +783,17 @@ class JavaPairRDD[K, V](val rdd: RDD[(K, V)])
     sortByKey(comp, ascending)
   }
 
+  /**
+   * 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
+   * (in the `save` case, they will be written to multiple `part-X` files in the filesystem, in
+   * order of the keys).
+   */
+  def sortByKey(ascending: Boolean, numPartitions: Int): JavaPairRDD[K, V] = {
+    val comp = com.google.common.collect.Ordering.natural().asInstanceOf[Comparator[K]]
+    sortByKey(comp, ascending, numPartitions)
+  }
+
   /**
    * 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
-- 
GitLab