The aggregateMessages operator

Once we have our graph ready, let's start our mission, which is aggregating the stats data in scoreGraph. In GraphX, aggregateMessages is the operator for that kind of job.

For example, let's find out the average field goals made per game by the winning teams. In other words, the games that the teams lost will not be counted. To get the average for each team, we first need to have the number of games won by the team and the total field goals that the team made in those games:

// Aggregate the total field goals made by winning teams type FGMsg = (Int, Int) val winningFieldGoalMade: VertexRDD[FGMsg] = scoreGraph aggregateMessages( // sendMsg triplet => triplet.sendToSrc(1, triplet.attr.winnerStats.fieldGoalMade) // mergeMsg ...

Get Apache Spark Graph Processing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.