{"action":"created","comment":{"url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/comments/24145593","id":24145593,"diff_hunk":"@@ -1796,6 +1830,79 @@ setMethod(\"cogroup\",\n                                      group.func)\n           })\n \n+#' Sort an (k, v) pair RDD by k.\n+#'\n+#' @param rdd An (k, v) pair RDD to be sorted.\n+#' @param ascending A flag to indicate whether the sorting is ascending or descending.\n+#' @param numPartitions Number of partitions to create.\n+#' @return An RDD where all (k, v) pair elements are sorted.\n+#' @rdname sortByKey\n+#' @export\n+#' @examples\n+#'\\dontrun{\n+#' sc <- sparkR.init()\n+#' rdd <- parallelize(sc, list(list(3, 3), list(2, 2), list(1, 1)))\n+#' collect(sortByKey(rdd)) # list (list(1, 1), list(2, 2), list(3, 3))\n+#'}\n+setGeneric(\"sortByKey\", function(rdd, ascending, numPartitions) { standardGeneric(\"sortByKey\") })\n+\n+#' @rdname sortByKey\n+#' @aliases sortByKey,RDD,RDD-method\n+setMethod(\"sortByKey\",\n+          signature(rdd = \"RDD\", ascending = \"missingOrLogical\", numPartitions = \"missingOrInteger\"),\n+          function(rdd, ascending, numPartitions) {\n+            if (missing(ascending)) {\n+              ascending = TRUE\n+            }\n+            if (missing(numPartitions)) {\n+              numPartitions = SparkR::numPartitions(rdd)\n+            }\n+\n+            rangeBounds <- list()\n+            \n+            if (numPartitions > 1) {\n+              rddSize <- count(rdd)\n+              # constant from Spark's RangePartitioner\n+              maxSampleSize <- numPartitions * 20\n+              fraction <- min(maxSampleSize / max(rddSize, 1), 1.0)\n+              \n+              samples <- collect(keys(sampleRDD(rdd, FALSE, fraction, 1L)))\n+              \n+              # Note: the built-in R sort() function only atomic vectors","path":"pkg/R/RDD.R","position":83,"original_position":83,"commit_id":"804355977ba387a036b9c5355156cf547e20a738","original_commit_id":"804355977ba387a036b9c5355156cf547e20a738","user":{"login":"concretevitamin","id":592670,"avatar_url":"https://avatars.githubusercontent.com/u/592670?v=3","gravatar_id":"","url":"https://api.github.com/users/concretevitamin","html_url":"https://github.com/concretevitamin","followers_url":"https://api.github.com/users/concretevitamin/followers","following_url":"https://api.github.com/users/concretevitamin/following{/other_user}","gists_url":"https://api.github.com/users/concretevitamin/gists{/gist_id}","starred_url":"https://api.github.com/users/concretevitamin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/concretevitamin/subscriptions","organizations_url":"https://api.github.com/users/concretevitamin/orgs","repos_url":"https://api.github.com/users/concretevitamin/repos","events_url":"https://api.github.com/users/concretevitamin/events{/privacy}","received_events_url":"https://api.github.com/users/concretevitamin/received_events","type":"User","site_admin":false},"body":"missing \"...works on...\"?","created_at":"2015-02-05T06:35:06Z","updated_at":"2015-02-05T06:35:06Z","html_url":"https://github.com/amplab-extras/SparkR-pkg/pull/154#discussion_r24145593","pull_request_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/154","_links":{"self":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/comments/24145593"},"html":{"href":"https://github.com/amplab-extras/SparkR-pkg/pull/154#discussion_r24145593"},"pull_request":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/154"}}},"pull_request":{"url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/154","id":28641103,"html_url":"https://github.com/amplab-extras/SparkR-pkg/pull/154","diff_url":"https://github.com/amplab-extras/SparkR-pkg/pull/154.diff","patch_url":"https://github.com/amplab-extras/SparkR-pkg/pull/154.patch","issue_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/154","number":154,"state":"open","locked":false,"title":"[SPARKR-150] phase 1: implement sortBy() and sortByKey().","user":{"login":"sun-rui","id":2528327,"avatar_url":"https://avatars.githubusercontent.com/u/2528327?v=3","gravatar_id":"","url":"https://api.github.com/users/sun-rui","html_url":"https://github.com/sun-rui","followers_url":"https://api.github.com/users/sun-rui/followers","following_url":"https://api.github.com/users/sun-rui/following{/other_user}","gists_url":"https://api.github.com/users/sun-rui/gists{/gist_id}","starred_url":"https://api.github.com/users/sun-rui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sun-rui/subscriptions","organizations_url":"https://api.github.com/users/sun-rui/orgs","repos_url":"https://api.github.com/users/sun-rui/repos","events_url":"https://api.github.com/users/sun-rui/events{/privacy}","received_events_url":"https://api.github.com/users/sun-rui/received_events","type":"User","site_admin":false},"body":"This is phase 1 patch for SPARKR-150. It implements sortBy() and sortByKey().\r\n\r\nBasically the rangePartitioner is the same as that in PySpark. It is simpler that the rangePartitioner in Spark, we can enhance it later if necessary.\r\n\r\nNow add only two test cases. Will add more test cases during review.","created_at":"2015-02-04T14:15:05Z","updated_at":"2015-02-05T06:35:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/154/commits","review_comments_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/154/comments","review_comment_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/comments/{number}","comments_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/154/comments","statuses_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/statuses/804355977ba387a036b9c5355156cf547e20a738","head":{"label":"sun-rui:SPARKR-150","ref":"SPARKR-150","sha":"804355977ba387a036b9c5355156cf547e20a738","user":{"login":"sun-rui","id":2528327,"avatar_url":"https://avatars.githubusercontent.com/u/2528327?v=3","gravatar_id":"","url":"https://api.github.com/users/sun-rui","html_url":"https://github.com/sun-rui","followers_url":"https://api.github.com/users/sun-rui/followers","following_url":"https://api.github.com/users/sun-rui/following{/other_user}","gists_url":"https://api.github.com/users/sun-rui/gists{/gist_id}","starred_url":"https://api.github.com/users/sun-rui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sun-rui/subscriptions","organizations_url":"https://api.github.com/users/sun-rui/orgs","repos_url":"https://api.github.com/users/sun-rui/repos","events_url":"https://api.github.com/users/sun-rui/events{/privacy}","received_events_url":"https://api.github.com/users/sun-rui/received_events","type":"User","site_admin":false},"repo":{"id":24314720,"name":"SparkR-pkg","full_name":"sun-rui/SparkR-pkg","owner":{"login":"sun-rui","id":2528327,"avatar_url":"https://avatars.githubusercontent.com/u/2528327?v=3","gravatar_id":"","url":"https://api.github.com/users/sun-rui","html_url":"https://github.com/sun-rui","followers_url":"https://api.github.com/users/sun-rui/followers","following_url":"https://api.github.com/users/sun-rui/following{/other_user}","gists_url":"https://api.github.com/users/sun-rui/gists{/gist_id}","starred_url":"https://api.github.com/users/sun-rui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sun-rui/subscriptions","organizations_url":"https://api.github.com/users/sun-rui/orgs","repos_url":"https://api.github.com/users/sun-rui/repos","events_url":"https://api.github.com/users/sun-rui/events{/privacy}","received_events_url":"https://api.github.com/users/sun-rui/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sun-rui/SparkR-pkg","description":"R frontend for Spark","fork":true,"url":"https://api.github.com/repos/sun-rui/SparkR-pkg","forks_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/forks","keys_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/teams","hooks_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/hooks","issue_events_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/issues/events{/number}","events_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/events","assignees_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/assignees{/user}","branches_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/branches{/branch}","tags_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/tags","blobs_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/git/refs{/sha}","trees_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/statuses/{sha}","languages_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/languages","stargazers_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/stargazers","contributors_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/contributors","subscribers_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/subscribers","subscription_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/subscription","commits_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/commits{/sha}","git_commits_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/git/commits{/sha}","comments_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/comments{/number}","issue_comment_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/issues/comments/{number}","contents_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/contents/{+path}","compare_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/merges","archive_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/downloads","issues_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/issues{/number}","pulls_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/pulls{/number}","milestones_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/milestones{/number}","notifications_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/labels{/name}","releases_url":"https://api.github.com/repos/sun-rui/SparkR-pkg/releases{/id}","created_at":"2014-09-22T04:51:58Z","updated_at":"2014-09-22T04:56:09Z","pushed_at":"2015-02-05T04:12:44Z","git_url":"git://github.com/sun-rui/SparkR-pkg.git","ssh_url":"git@github.com:sun-rui/SparkR-pkg.git","clone_url":"https://github.com/sun-rui/SparkR-pkg.git","svn_url":"https://github.com/sun-rui/SparkR-pkg","homepage":"http://amplab-extras.github.io/SparkR-pkg","size":3550,"stargazers_count":0,"watchers_count":0,"language":"R","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"amplab-extras:master","ref":"master","sha":"08ff30b14f86974ac085bd0e9ab95e536839bfc8","user":{"login":"amplab-extras","id":6403540,"avatar_url":"https://avatars.githubusercontent.com/u/6403540?v=3","gravatar_id":"","url":"https://api.github.com/users/amplab-extras","html_url":"https://github.com/amplab-extras","followers_url":"https://api.github.com/users/amplab-extras/followers","following_url":"https://api.github.com/users/amplab-extras/following{/other_user}","gists_url":"https://api.github.com/users/amplab-extras/gists{/gist_id}","starred_url":"https://api.github.com/users/amplab-extras/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplab-extras/subscriptions","organizations_url":"https://api.github.com/users/amplab-extras/orgs","repos_url":"https://api.github.com/users/amplab-extras/repos","events_url":"https://api.github.com/users/amplab-extras/events{/privacy}","received_events_url":"https://api.github.com/users/amplab-extras/received_events","type":"Organization","site_admin":false},"repo":{"id":15365789,"name":"SparkR-pkg","full_name":"amplab-extras/SparkR-pkg","owner":{"login":"amplab-extras","id":6403540,"avatar_url":"https://avatars.githubusercontent.com/u/6403540?v=3","gravatar_id":"","url":"https://api.github.com/users/amplab-extras","html_url":"https://github.com/amplab-extras","followers_url":"https://api.github.com/users/amplab-extras/followers","following_url":"https://api.github.com/users/amplab-extras/following{/other_user}","gists_url":"https://api.github.com/users/amplab-extras/gists{/gist_id}","starred_url":"https://api.github.com/users/amplab-extras/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplab-extras/subscriptions","organizations_url":"https://api.github.com/users/amplab-extras/orgs","repos_url":"https://api.github.com/users/amplab-extras/repos","events_url":"https://api.github.com/users/amplab-extras/events{/privacy}","received_events_url":"https://api.github.com/users/amplab-extras/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/amplab-extras/SparkR-pkg","description":"R frontend for Spark","fork":false,"url":"https://api.github.com/repos/amplab-extras/SparkR-pkg","forks_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/forks","keys_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/teams","hooks_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/hooks","issue_events_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/events{/number}","events_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/events","assignees_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/assignees{/user}","branches_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/branches{/branch}","tags_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/tags","blobs_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/git/refs{/sha}","trees_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/statuses/{sha}","languages_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/languages","stargazers_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/stargazers","contributors_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/contributors","subscribers_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/subscribers","subscription_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/subscription","commits_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/commits{/sha}","git_commits_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/git/commits{/sha}","comments_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/comments{/number}","issue_comment_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/comments/{number}","contents_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/contents/{+path}","compare_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/merges","archive_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/downloads","issues_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues{/number}","pulls_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls{/number}","milestones_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/milestones{/number}","notifications_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/labels{/name}","releases_url":"https://api.github.com/repos/amplab-extras/SparkR-pkg/releases{/id}","created_at":"2013-12-21T21:16:54Z","updated_at":"2015-02-04T06:48:58Z","pushed_at":"2015-02-04T18:51:34Z","git_url":"git://github.com/amplab-extras/SparkR-pkg.git","ssh_url":"git@github.com:amplab-extras/SparkR-pkg.git","clone_url":"https://github.com/amplab-extras/SparkR-pkg.git","svn_url":"https://github.com/amplab-extras/SparkR-pkg","homepage":"http://amplab-extras.github.io/SparkR-pkg","size":4639,"stargazers_count":382,"watchers_count":382,"language":"R","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":133,"mirror_url":null,"open_issues_count":22,"forks":133,"open_issues":22,"watchers":382,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/154"},"html":{"href":"https://github.com/amplab-extras/SparkR-pkg/pull/154"},"issue":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/154"},"comments":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/issues/154/comments"},"review_comments":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/154/comments"},"review_comment":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/pulls/154/commits"},"statuses":{"href":"https://api.github.com/repos/amplab-extras/SparkR-pkg/statuses/804355977ba387a036b9c5355156cf547e20a738"}}}}