Skip to content

Instantly share code, notes, and snippets.

@rjurney
Created March 25, 2025 17:10
GraphFrames Pregel API - sum the ages of a node's neighbors
from graphframes.lib import AggregateMessages as AM
from graphframes.examples import Graphs
from pyspark.sql.functions import sum as sqlsum
g = Graphs(spark).friends() # Get example graph
# For each user, sum the ages of the adjacent users
msgToSrc = AM.dst["age"]
msgToDst = AM.src["age"]
agg = g.aggregateMessages(
sqlsum(AM.msg).alias("summedAges"),
sendToSrc=msgToSrc,
sendToDst=msgToDst)
agg.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment