GraphX中图形中每个分区的顶点数

时间:2017-09-27 14:15:20

标签: scala apache-spark pyspark spark-graphx

如何计算图表中每个分区中的顶点数?

在RDD中火花有

  

.mapPartition,

GraphX中的图形没有类似的 .mapPartitionVertices ,因此您无法计算它们在分区中的元素数量。

我想知道你是否有更好的方法去做顶点,然后手动检查:

  

graph.vertices.mapPartitions

1 个答案:

答案 0 :(得分:1)

VertexRDD类没有转换方法来操作分区,但是您可以应用map转换来获取RDD对象,然后计算每个分区的记录数。地图转换不会改变每个分区的元素和元素数量。

<强> E.g。

val countRDD = graph.vertices.map{ case (id, attr) => (id, attr) }
.mapPartitionsWithIndex{case (i,rows) => Iterator((i,rows.size))}

countRDD.collect()
相关问题