>我正在通过教程运行http://ampcamp.berkeley.edu/big-data-mini-course/graph-analytics-with-graphx.html
在某些时候,我们使用mapReduceTriplet操作。这将返回预期的结果
// Find the oldest follower for each user
val oldestFollower: VertexRDD[(String, Int)] = userGraph.mapReduceTriplets[(String, Int)](
// For each edge send a message to the destination vertex with the attribute of the source vertex
edge => Iterator((edge.dstId, (edge.srcAttr.name, edge.srcAttr.age))),
// To combine messages take the message for the older follower
(a, b) => if (a._2 > b._2) a else b
)
但是IntelliJ指出mapReduceTriplet已被弃用(从1.2.0开始),应该被aggregateMessages取代
。// Find the oldest follower for each user
val oldestFollower: VertexRDD[(String, Int)] = userGraph.aggregateMessages()[(String, Int)](
// For each edge send a message to the destination vertex with the attribute of the source vertex
edge => Iterator((edge.dstId, (edge.srcAttr.name, edge.srcAttr.age))),
// To combine messages take the message for the older follower
(a, b) => if (a._2 > b._2) a else b
)
所以我运行完全相同的代码,但没有任何输出。这是预期的结果,还是我应该由于聚合消息的混乱而更改某些内容?
可能需要这样的东西:
val oldestFollower: VertexRDD[(String, Int)] = userGraph.aggregateMessages[(String, Int)]
(
// For each edge send a message to the destination vertex with the attribute of the source vertex
sendMsg = { triplet => triplet.sendToDst(triplet.srcAttr.name, triplet.srcAttr.age) },
// To combine messages take the message for the older follower
mergeMsg = {(a, b) => if (a._2 > b._2) a else b}
)
您可以在 Grapx 编程指南页面上找到aggregateMessages
函数签名和有用的示例。希望这有帮助。