{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/34736588","id":34736588,"diff_hunk":"@@ -82,20 +84,70 @@ class PrefixSpan private (\n       logWarning(\"Input data is not cached.\")\n     }\n     val minCount = getMinCount(sequences)\n-    val lengthOnePatternsAndCounts =\n-      getFreqItemAndCounts(minCount, sequences).collect()\n-    val prefixAndProjectedDatabase = getPrefixAndProjectedDatabase(\n-      lengthOnePatternsAndCounts.map(_._1), sequences)\n-    val groupedProjectedDatabase = prefixAndProjectedDatabase\n-      .map(x => (x._1.toSeq, x._2))\n-      .groupByKey()\n-      .map(x => (x._1.toArray, x._2.toArray))\n-    val nextPatterns = getPatternsInLocal(minCount, groupedProjectedDatabase)\n-    val lengthOnePatternsAndCountsRdd =\n-      sequences.sparkContext.parallelize(\n-        lengthOnePatternsAndCounts.map(x => (Array(x._1), x._2)))\n-    val allPatterns = lengthOnePatternsAndCountsRdd ++ nextPatterns\n-    allPatterns\n+    val lengthOnePatternsAndCounts = getFreqItemAndCounts(minCount, sequences)\n+    val prefixSuffixPairs = getPrefixSuffixPairs(\n+      lengthOnePatternsAndCounts.map(_._1).collect(), sequences)\n+    var patternsCount: Long = lengthOnePatternsAndCounts.count()\n+    var allPatternAndCounts = lengthOnePatternsAndCounts.map(x => (Array(x._1), x._2))\n+    var currentPrefixSuffixPairs = prefixSuffixPairs\n+    while (patternsCount <= minPatternsBeforeShuffle && currentPrefixSuffixPairs.count() != 0) {\n+      val (nextPatternAndCounts, nextPrefixSuffixPairs) =\n+        getPatternCountsAndPrefixSuffixPairs(minCount, currentPrefixSuffixPairs)\n+      patternsCount = nextPatternAndCounts.count().toInt\n+      currentPrefixSuffixPairs = nextPrefixSuffixPairs\n+      allPatternAndCounts = allPatternAndCounts ++ nextPatternAndCounts\n+    }\n+    if (patternsCount > 0) {\n+      val projectedDatabase = currentPrefixSuffixPairs\n+        .map(x => (x._1.toSeq, x._2))\n+        .groupByKey()\n+        .map(x => (x._1.toArray, x._2.toArray))\n+      val nextPatternAndCounts = getPatternsInLocal(minCount, projectedDatabase)\n+      allPatternAndCounts = allPatternAndCounts ++ nextPatternAndCounts\n+    }\n+    allPatternAndCounts\n+  }\n+\n+  /**\n+   * Get the pattern and counts, and prefix suffix pairs\n+   * @param minCount minimum count\n+   * @param prefixSuffixPairs prefix and suffix pairs,\n+   * @return pattern and counts, and prefix suffix pairs\n+   *         (Array[pattern, count], RDD[prefix, suffix ])\n+   */\n+  private def getPatternCountsAndPrefixSuffixPairs(\n+      minCount: Long,\n+      prefixSuffixPairs: RDD[(Array[Int], Array[Int])]):\n+  (RDD[(Array[Int], Long)], RDD[(Array[Int], Array[Int])]) = {\n+    val prefixAndFreqentItemAndCounts = prefixSuffixPairs\n+      .flatMap { case (prefix, suffix) =>\n+      suffix.distinct.map(y => ((prefix.toSeq, y), 1L))\n+    }.reduceByKey(_ + _)\n+      .filter(_._2 >= minCount)\n+    val patternAndCounts = prefixAndFreqentItemAndCounts\n+      .map{ case ((prefix, item), count) => (prefix.toArray :+ item, count) }\n+    val prefixlength = prefixSuffixPairs.first()._1.length\n+    if (prefixlength + 1 >= maxPatternLength) {\n+      (patternAndCounts, prefixSuffixPairs.filter(x => false))\n+    } else {\n+      val frequentItemsMap = prefixAndFreqentItemAndCounts","path":"mllib/src/main/scala/org/apache/spark/mllib/fpm/PrefixSpan.scala","position":73,"original_position":73,"commit_id":"baa2885681f19897cc5158f4fc9338543a55487a","original_commit_id":"baa2885681f19897cc5158f4fc9338543a55487a","user":{"login":"feynmanliang","id":990069,"avatar_url":"https://avatars.githubusercontent.com/u/990069?v=3","gravatar_id":"","url":"https://api.github.com/users/feynmanliang","html_url":"https://github.com/feynmanliang","followers_url":"https://api.github.com/users/feynmanliang/followers","following_url":"https://api.github.com/users/feynmanliang/following{/other_user}","gists_url":"https://api.github.com/users/feynmanliang/gists{/gist_id}","starred_url":"https://api.github.com/users/feynmanliang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feynmanliang/subscriptions","organizations_url":"https://api.github.com/users/feynmanliang/orgs","repos_url":"https://api.github.com/users/feynmanliang/repos","events_url":"https://api.github.com/users/feynmanliang/events{/privacy}","received_events_url":"https://api.github.com/users/feynmanliang/received_events","type":"User","site_admin":false},"body":"`frequentItemsMap` -> `prefixToFrequentNextItemsMap`","created_at":"2015-07-15T22:19:14Z","updated_at":"2015-07-15T22:19:14Z","html_url":"https://github.com/apache/spark/pull/7412#discussion_r34736588","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/7412","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/34736588"},"html":{"href":"https://github.com/apache/spark/pull/7412#discussion_r34736588"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/7412"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/7412","id":39986032,"html_url":"https://github.com/apache/spark/pull/7412","diff_url":"https://github.com/apache/spark/pull/7412.diff","patch_url":"https://github.com/apache/spark/pull/7412.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/7412","number":7412,"state":"open","locked":false,"title":"[SPARK-8998][MLlib] Collect enough frequent prefixes before local processing in PrefixSpan (new)","user":{"login":"zhangjiajin","id":13159256,"avatar_url":"https://avatars.githubusercontent.com/u/13159256?v=3","gravatar_id":"","url":"https://api.github.com/users/zhangjiajin","html_url":"https://github.com/zhangjiajin","followers_url":"https://api.github.com/users/zhangjiajin/followers","following_url":"https://api.github.com/users/zhangjiajin/following{/other_user}","gists_url":"https://api.github.com/users/zhangjiajin/gists{/gist_id}","starred_url":"https://api.github.com/users/zhangjiajin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhangjiajin/subscriptions","organizations_url":"https://api.github.com/users/zhangjiajin/orgs","repos_url":"https://api.github.com/users/zhangjiajin/repos","events_url":"https://api.github.com/users/zhangjiajin/events{/privacy}","received_events_url":"https://api.github.com/users/zhangjiajin/received_events","type":"User","site_admin":false},"body":"Collect enough frequent prefixes before projection in PrefixSpan","created_at":"2015-07-15T03:51:54Z","updated_at":"2015-07-15T22:19:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"118d5575845eb78bf8887276a1605cb9673bb35d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/7412/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/7412/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/7412/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/baa2885681f19897cc5158f4fc9338543a55487a","head":{"label":"zhangjiajin:CollectEnoughPrefixes","ref":"CollectEnoughPrefixes","sha":"baa2885681f19897cc5158f4fc9338543a55487a","user":{"login":"zhangjiajin","id":13159256,"avatar_url":"https://avatars.githubusercontent.com/u/13159256?v=3","gravatar_id":"","url":"https://api.github.com/users/zhangjiajin","html_url":"https://github.com/zhangjiajin","followers_url":"https://api.github.com/users/zhangjiajin/followers","following_url":"https://api.github.com/users/zhangjiajin/following{/other_user}","gists_url":"https://api.github.com/users/zhangjiajin/gists{/gist_id}","starred_url":"https://api.github.com/users/zhangjiajin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhangjiajin/subscriptions","organizations_url":"https://api.github.com/users/zhangjiajin/orgs","repos_url":"https://api.github.com/users/zhangjiajin/repos","events_url":"https://api.github.com/users/zhangjiajin/events{/privacy}","received_events_url":"https://api.github.com/users/zhangjiajin/received_events","type":"User","site_admin":false},"repo":{"id":38591062,"name":"spark","full_name":"zhangjiajin/spark","owner":{"login":"zhangjiajin","id":13159256,"avatar_url":"https://avatars.githubusercontent.com/u/13159256?v=3","gravatar_id":"","url":"https://api.github.com/users/zhangjiajin","html_url":"https://github.com/zhangjiajin","followers_url":"https://api.github.com/users/zhangjiajin/followers","following_url":"https://api.github.com/users/zhangjiajin/following{/other_user}","gists_url":"https://api.github.com/users/zhangjiajin/gists{/gist_id}","starred_url":"https://api.github.com/users/zhangjiajin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhangjiajin/subscriptions","organizations_url":"https://api.github.com/users/zhangjiajin/orgs","repos_url":"https://api.github.com/users/zhangjiajin/repos","events_url":"https://api.github.com/users/zhangjiajin/events{/privacy}","received_events_url":"https://api.github.com/users/zhangjiajin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zhangjiajin/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/zhangjiajin/spark","forks_url":"https://api.github.com/repos/zhangjiajin/spark/forks","keys_url":"https://api.github.com/repos/zhangjiajin/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zhangjiajin/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zhangjiajin/spark/teams","hooks_url":"https://api.github.com/repos/zhangjiajin/spark/hooks","issue_events_url":"https://api.github.com/repos/zhangjiajin/spark/issues/events{/number}","events_url":"https://api.github.com/repos/zhangjiajin/spark/events","assignees_url":"https://api.github.com/repos/zhangjiajin/spark/assignees{/user}","branches_url":"https://api.github.com/repos/zhangjiajin/spark/branches{/branch}","tags_url":"https://api.github.com/repos/zhangjiajin/spark/tags","blobs_url":"https://api.github.com/repos/zhangjiajin/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zhangjiajin/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zhangjiajin/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/zhangjiajin/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zhangjiajin/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/zhangjiajin/spark/languages","stargazers_url":"https://api.github.com/repos/zhangjiajin/spark/stargazers","contributors_url":"https://api.github.com/repos/zhangjiajin/spark/contributors","subscribers_url":"https://api.github.com/repos/zhangjiajin/spark/subscribers","subscription_url":"https://api.github.com/repos/zhangjiajin/spark/subscription","commits_url":"https://api.github.com/repos/zhangjiajin/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/zhangjiajin/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/zhangjiajin/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/zhangjiajin/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/zhangjiajin/spark/contents/{+path}","compare_url":"https://api.github.com/repos/zhangjiajin/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zhangjiajin/spark/merges","archive_url":"https://api.github.com/repos/zhangjiajin/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zhangjiajin/spark/downloads","issues_url":"https://api.github.com/repos/zhangjiajin/spark/issues{/number}","pulls_url":"https://api.github.com/repos/zhangjiajin/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/zhangjiajin/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/zhangjiajin/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zhangjiajin/spark/labels{/name}","releases_url":"https://api.github.com/repos/zhangjiajin/spark/releases{/id}","created_at":"2015-07-06T01:29:00Z","updated_at":"2015-07-06T01:29:21Z","pushed_at":"2015-07-15T08:52:04Z","git_url":"git://github.com/zhangjiajin/spark.git","ssh_url":"git@github.com:zhangjiajin/spark.git","clone_url":"https://github.com/zhangjiajin/spark.git","svn_url":"https://github.com/zhangjiajin/spark","homepage":null,"size":112628,"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":"bb870e72f42b6ce8d056df259f6fcf41808d7ed2","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}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-07-15T20:36:52Z","pushed_at":"2015-07-15T21:59:51Z","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":1538619,"stargazers_count":4761,"watchers_count":4761,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4245,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":338,"forks":4245,"open_issues":338,"watchers":4761,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/7412"},"html":{"href":"https://github.com/apache/spark/pull/7412"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/7412"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/7412/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/7412/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/7412/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/baa2885681f19897cc5158f4fc9338543a55487a"}}}}