O'Reilly logo

Apache Spark Graph Processing by Rindra Ramamonjison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required