{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/59119677","id":59119677,"diff_hunk":"@@ -152,16 +152,10 @@ class CountVectorizer(override val uid: String)\n       (word, count)\n     }.cache()\n     val fullVocabSize = wordCounts.count()\n-    val vocab: Array[String] = {\n-      val tmpSortedWC: Array[(String, Long)] = if (fullVocabSize <= vocSize) {\n-        // Use all terms\n-        wordCounts.collect().sortBy(-_._2)\n-      } else {\n-        // Sort terms to select vocab\n-        wordCounts.sortBy(_._2, ascending = false).take(vocSize)\n-      }\n-      tmpSortedWC.map(_._1)\n-    }\n+\n+    val vocab: Array[String] = wordCounts.\n+    top(math.min(fullVocabSize, vocSize).toInt)(Ordering.by(_._2))","path":"mllib/src/main/scala/org/apache/spark/ml/feature/CountVectorizer.scala","position":16,"original_position":16,"commit_id":"38d7c876d81de87a9c51e1f63dcb4d288ff02955","original_commit_id":"38d7c876d81de87a9c51e1f63dcb4d288ff02955","user":{"login":"mengxr","id":829644,"avatar_url":"https://avatars.githubusercontent.com/u/829644?v=3","gravatar_id":"","url":"https://api.github.com/users/mengxr","html_url":"https://github.com/mengxr","followers_url":"https://api.github.com/users/mengxr/followers","following_url":"https://api.github.com/users/mengxr/following{/other_user}","gists_url":"https://api.github.com/users/mengxr/gists{/gist_id}","starred_url":"https://api.github.com/users/mengxr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mengxr/subscriptions","organizations_url":"https://api.github.com/users/mengxr/orgs","repos_url":"https://api.github.com/users/mengxr/repos","events_url":"https://api.github.com/users/mengxr/events{/privacy}","received_events_url":"https://api.github.com/users/mengxr/received_events","type":"User","site_admin":false},"body":"@lionelfeng Please use the following style (moving `.` to next line and fix indentation):\r\n\r\n~~~scala\r\nval vocab: Array[String] = wordCounts\r\n  .top(math.min(fullVocabSize, vocSize).toInt)(Ordering.by(_._2))\r\n  .map(_._1)\r\n~~~","created_at":"2016-04-09T19:02:06Z","updated_at":"2016-04-09T19:02:06Z","html_url":"https://github.com/apache/spark/pull/12265#discussion_r59119677","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/12265","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/59119677"},"html":{"href":"https://github.com/apache/spark/pull/12265#discussion_r59119677"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/12265"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/12265","id":65844085,"html_url":"https://github.com/apache/spark/pull/12265","diff_url":"https://github.com/apache/spark/pull/12265.diff","patch_url":"https://github.com/apache/spark/pull/12265.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/12265","number":12265,"state":"open","locked":false,"title":"[SPARK-14497][ML] Use top instead of sortBy() to get top N frequent words as dict in ConutVectorizer","user":{"login":"lionelfeng","id":3171807,"avatar_url":"https://avatars.githubusercontent.com/u/3171807?v=3","gravatar_id":"","url":"https://api.github.com/users/lionelfeng","html_url":"https://github.com/lionelfeng","followers_url":"https://api.github.com/users/lionelfeng/followers","following_url":"https://api.github.com/users/lionelfeng/following{/other_user}","gists_url":"https://api.github.com/users/lionelfeng/gists{/gist_id}","starred_url":"https://api.github.com/users/lionelfeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lionelfeng/subscriptions","organizations_url":"https://api.github.com/users/lionelfeng/orgs","repos_url":"https://api.github.com/users/lionelfeng/repos","events_url":"https://api.github.com/users/lionelfeng/events{/privacy}","received_events_url":"https://api.github.com/users/lionelfeng/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nReplace sortBy() with top() to calculate the top N frequent words as dictionary.\r\n\r\n## How was this patch tested?\r\nexisting unit tests.  The terms with same TF would be sorted in descending order. The test would fail if hardcode the terms with same TF the dictionary like \"c\", \"d\"...\r\n\r\n\r\n","created_at":"2016-04-08T20:38:45Z","updated_at":"2016-04-09T19:02:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bf54f39dadb8b4c89c863262c9f26c2e87862cd4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/12265/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/12265/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/12265/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/38d7c876d81de87a9c51e1f63dcb4d288ff02955","head":{"label":"lionelfeng:master","ref":"master","sha":"38d7c876d81de87a9c51e1f63dcb4d288ff02955","user":{"login":"lionelfeng","id":3171807,"avatar_url":"https://avatars.githubusercontent.com/u/3171807?v=3","gravatar_id":"","url":"https://api.github.com/users/lionelfeng","html_url":"https://github.com/lionelfeng","followers_url":"https://api.github.com/users/lionelfeng/followers","following_url":"https://api.github.com/users/lionelfeng/following{/other_user}","gists_url":"https://api.github.com/users/lionelfeng/gists{/gist_id}","starred_url":"https://api.github.com/users/lionelfeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lionelfeng/subscriptions","organizations_url":"https://api.github.com/users/lionelfeng/orgs","repos_url":"https://api.github.com/users/lionelfeng/repos","events_url":"https://api.github.com/users/lionelfeng/events{/privacy}","received_events_url":"https://api.github.com/users/lionelfeng/received_events","type":"User","site_admin":false},"repo":{"id":55745923,"name":"spark","full_name":"lionelfeng/spark","owner":{"login":"lionelfeng","id":3171807,"avatar_url":"https://avatars.githubusercontent.com/u/3171807?v=3","gravatar_id":"","url":"https://api.github.com/users/lionelfeng","html_url":"https://github.com/lionelfeng","followers_url":"https://api.github.com/users/lionelfeng/followers","following_url":"https://api.github.com/users/lionelfeng/following{/other_user}","gists_url":"https://api.github.com/users/lionelfeng/gists{/gist_id}","starred_url":"https://api.github.com/users/lionelfeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lionelfeng/subscriptions","organizations_url":"https://api.github.com/users/lionelfeng/orgs","repos_url":"https://api.github.com/users/lionelfeng/repos","events_url":"https://api.github.com/users/lionelfeng/events{/privacy}","received_events_url":"https://api.github.com/users/lionelfeng/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lionelfeng/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/lionelfeng/spark","forks_url":"https://api.github.com/repos/lionelfeng/spark/forks","keys_url":"https://api.github.com/repos/lionelfeng/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lionelfeng/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lionelfeng/spark/teams","hooks_url":"https://api.github.com/repos/lionelfeng/spark/hooks","issue_events_url":"https://api.github.com/repos/lionelfeng/spark/issues/events{/number}","events_url":"https://api.github.com/repos/lionelfeng/spark/events","assignees_url":"https://api.github.com/repos/lionelfeng/spark/assignees{/user}","branches_url":"https://api.github.com/repos/lionelfeng/spark/branches{/branch}","tags_url":"https://api.github.com/repos/lionelfeng/spark/tags","blobs_url":"https://api.github.com/repos/lionelfeng/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lionelfeng/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lionelfeng/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/lionelfeng/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lionelfeng/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/lionelfeng/spark/languages","stargazers_url":"https://api.github.com/repos/lionelfeng/spark/stargazers","contributors_url":"https://api.github.com/repos/lionelfeng/spark/contributors","subscribers_url":"https://api.github.com/repos/lionelfeng/spark/subscribers","subscription_url":"https://api.github.com/repos/lionelfeng/spark/subscription","commits_url":"https://api.github.com/repos/lionelfeng/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/lionelfeng/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/lionelfeng/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/lionelfeng/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/lionelfeng/spark/contents/{+path}","compare_url":"https://api.github.com/repos/lionelfeng/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lionelfeng/spark/merges","archive_url":"https://api.github.com/repos/lionelfeng/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lionelfeng/spark/downloads","issues_url":"https://api.github.com/repos/lionelfeng/spark/issues{/number}","pulls_url":"https://api.github.com/repos/lionelfeng/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/lionelfeng/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/lionelfeng/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lionelfeng/spark/labels{/name}","releases_url":"https://api.github.com/repos/lionelfeng/spark/releases{/id}","deployments_url":"https://api.github.com/repos/lionelfeng/spark/deployments","created_at":"2016-04-08T03:06:26Z","updated_at":"2016-04-08T03:06:47Z","pushed_at":"2016-04-09T18:42:43Z","git_url":"git://github.com/lionelfeng/spark.git","ssh_url":"git@github.com:lionelfeng/spark.git","clone_url":"https://github.com/lionelfeng/spark.git","svn_url":"https://github.com/lionelfeng/spark","homepage":null,"size":158057,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"02757535b58069ce8258108d89d8172a53c358e5","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2016-04-09T18:34:02Z","pushed_at":"2016-04-09T18:56:22Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":454800,"stargazers_count":8066,"watchers_count":8066,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7467,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":424,"forks":7467,"open_issues":424,"watchers":8066,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/12265"},"html":{"href":"https://github.com/apache/spark/pull/12265"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/12265"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/12265/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/12265/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/12265/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/38d7c876d81de87a9c51e1f63dcb4d288ff02955"}}}}