Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-26757][GraphX] Return 0 for count on empty Edge/Vertex RDDs #23681

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class EdgeRDDImpl[ED: ClassTag, VD: ClassTag] private[graphx] (

/** The number of edges in the RDD. */
override def count(): Long = {
partitionsRDD.map(_._2.size.toLong).reduce(_ + _)
partitionsRDD.map(_._2.size.toLong).fold(0)(_ + _)
huonw marked this conversation as resolved.
Show resolved Hide resolved
}

override def mapValues[ED2: ClassTag](f: Edge[ED] => ED2): EdgeRDDImpl[ED2, VD] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class VertexRDDImpl[VD] private[graphx] (

/** The number of vertices in the RDD. */
override def count(): Long = {
partitionsRDD.map(_.size.toLong).reduce(_ + _)
partitionsRDD.map(_.size.toLong).fold(0)(_ + _)
}

override private[graphx] def mapVertexPartitions[VD2: ClassTag](
Expand Down
11 changes: 11 additions & 0 deletions graphx/src/test/scala/org/apache/spark/graphx/EdgeRDDSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,15 @@ class EdgeRDDSuite extends SparkFunSuite with LocalSparkContext {
}
}

test("count") {
withSpark { sc =>
val empty = EdgeRDD.fromEdges(sc.emptyRDD[Edge[Int]])
assert(empty.count === 0)

val n = 100
huonw marked this conversation as resolved.
Show resolved Hide resolved
val edges = List(Edge(0, 1, ()), Edge(1, 2, ()), Edge(2, 0, ()))
val nonempty = EdgeRDD.fromEdges(sc.parallelize(edges))
assert(nonempty.count === edges.size)
}
}
}
11 changes: 11 additions & 0 deletions graphx/src/test/scala/org/apache/spark/graphx/VertexRDDSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,15 @@ class VertexRDDSuite extends SparkFunSuite with LocalSparkContext {
assert(verts.collect().toSeq === data) // test checkpointed RDD
}
}

test("count") {
withSpark { sc =>
val empty = VertexRDD(sc.emptyRDD[(Long, Unit)])
assert(empty.count === 0)

val n = 100
val nonempty = vertices(sc, n)
assert(nonempty.count === n + 1)
}
}
}