Created
March 25, 2025 17:10
-
-
Save rjurney/61bb36265cf6eefdb9cf06b80be973b1 to your computer and use it in GitHub Desktop.
GraphFrames Pregel API - sum the ages of a node's neighbors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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