You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by rx...@apache.org on 2016/03/29 06:00:02 UTC

spark git commit: [SPARK-14219][GRAPHX] Fix `pickRandomVertex` not to fall into infinit…

Repository: spark
Updated Branches:
  refs/heads/branch-1.6 504b99262 -> a7579444d


[SPARK-14219][GRAPHX] Fix `pickRandomVertex` not to fall into infinit…

## What changes were proposed in this pull request?

Currently, `GraphOps.pickRandomVertex()` falls into infinite loops for graphs having only one vertex. This PR fixes it by modifying the following termination-checking condition.
```scala
-      if (selectedVertices.count > 1) {
+      if (selectedVertices.count > 0) {
```

## How was this patch tested?

Pass the Jenkins tests (including new test case).

Author: Dongjoon Hyun <do...@apache.org>

Closes #12021 from dongjoon-hyun/SPARK-14219-2.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/a7579444
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/a7579444
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/a7579444

Branch: refs/heads/branch-1.6
Commit: a7579444d577f4f53ee2ce1470764126b175ba21
Parents: 504b992
Author: Dongjoon Hyun <do...@apache.org>
Authored: Mon Mar 28 21:00:00 2016 -0700
Committer: Reynold Xin <rx...@databricks.com>
Committed: Mon Mar 28 21:00:00 2016 -0700

----------------------------------------------------------------------
 graphx/src/main/scala/org/apache/spark/graphx/GraphOps.scala | 2 +-
 .../src/test/scala/org/apache/spark/graphx/GraphSuite.scala  | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/a7579444/graphx/src/main/scala/org/apache/spark/graphx/GraphOps.scala
----------------------------------------------------------------------
diff --git a/graphx/src/main/scala/org/apache/spark/graphx/GraphOps.scala b/graphx/src/main/scala/org/apache/spark/graphx/GraphOps.scala
index 9827dfa..e27c44d 100644
--- a/graphx/src/main/scala/org/apache/spark/graphx/GraphOps.scala
+++ b/graphx/src/main/scala/org/apache/spark/graphx/GraphOps.scala
@@ -269,7 +269,7 @@ class GraphOps[VD: ClassTag, ED: ClassTag](graph: Graph[VD, ED]) extends Seriali
         if (Random.nextDouble() < probability) { Some(vidVvals._1) }
         else { None }
       }
-      if (selectedVertices.count > 1) {
+      if (selectedVertices.count > 0) {
         found = true
         val collectedVertices = selectedVertices.collect()
         retVal = collectedVertices(Random.nextInt(collectedVertices.size))

http://git-wip-us.apache.org/repos/asf/spark/blob/a7579444/graphx/src/test/scala/org/apache/spark/graphx/GraphSuite.scala
----------------------------------------------------------------------
diff --git a/graphx/src/test/scala/org/apache/spark/graphx/GraphSuite.scala b/graphx/src/test/scala/org/apache/spark/graphx/GraphSuite.scala
index 1f5e27d..9acbd79 100644
--- a/graphx/src/test/scala/org/apache/spark/graphx/GraphSuite.scala
+++ b/graphx/src/test/scala/org/apache/spark/graphx/GraphSuite.scala
@@ -428,4 +428,12 @@ class GraphSuite extends SparkFunSuite with LocalSparkContext {
     }
   }
 
+  test("SPARK-14219: pickRandomVertex") {
+    withSpark { sc =>
+      val vert = sc.parallelize(List((1L, "a")), 1)
+      val edges = sc.parallelize(List(Edge[Long](1L, 1L)), 1)
+      val g0 = Graph(vert, edges)
+      assert(g0.pickRandomVertex() === 1L)
+    }
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org