【发布时间】:2021-06-25 12:20:18
【问题描述】:
以下是来自https://graphframes.github.io/graphframes/docs/_site/user-guide.html的示例
我唯一困惑的是条件函数中“lit(0)”的目的 如果这个“lit(0)”意味着输入“cnt”?如果是,为什么在 ["ab","bc","cd"] 之后?
from pyspark.sql.functions import col, lit, when
from pyspark.sql.types import IntegerType
from graphframes.examples import Graphs
from functools import reduce
chain4 = g.find("(a)-[ab]->(b); (b)-[bc]->(c); (c)-[cd]->(d)")
chain4.show()
sumFriends = lambda cnt,relationship: when(relationship == "friend", cnt+1).otherwise(cnt)
condition = reduce(lambda cnt,e: sumFriends(cnt, col(e).relationship), ["ab", "bc", "cd"], lit(0))
chainWith2Friends2 = chain4.where(condition >= 2)
chainWith2Friends2.show()
【问题讨论】:
标签: python lambda pyspark reduce graphframes