Repository: spark
Updated Branches:
refs/heads/master 2bc7c96d6 -> 289257c4c
[SPARK-14219][GRAPHX] Fix `pickRandomVertex` not to fall into infinite loops
for graphs with one vertex
## 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 <[email protected]>
Closes #12018 from dongjoon-hyun/SPARK-14219.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/289257c4
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/289257c4
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/289257c4
Branch: refs/heads/master
Commit: 289257c4c6005779e416b23e593c61e6531b2d9a
Parents: 2bc7c96
Author: Dongjoon Hyun <[email protected]>
Authored: Mon Mar 28 17:38:45 2016 -0700
Committer: Reynold Xin <[email protected]>
Committed: Mon Mar 28 17:38:45 2016 -0700
----------------------------------------------------------------------
.../src/main/scala/org/apache/spark/graphx/GraphOps.scala | 2 +-
.../src/test/scala/org/apache/spark/graphx/GraphSuite.scala | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/289257c4/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 fcb1b59..a783fe3 100644
--- a/graphx/src/main/scala/org/apache/spark/graphx/GraphOps.scala
+++ b/graphx/src/main/scala/org/apache/spark/graphx/GraphOps.scala
@@ -276,7 +276,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.length))
http://git-wip-us.apache.org/repos/asf/spark/blob/289257c4/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 cb98179..96aa262 100644
--- a/graphx/src/test/scala/org/apache/spark/graphx/GraphSuite.scala
+++ b/graphx/src/test/scala/org/apache/spark/graphx/GraphSuite.scala
@@ -404,4 +404,13 @@ class GraphSuite extends SparkFunSuite with
LocalSparkContext {
assert(sc.getPersistentRDDs.isEmpty)
}
}
+
+ 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: [email protected]
For additional commands, e-mail: [email protected]