scala - 如何在 GraphX 中使用 2 步连接计算入度
问题描述
我有一个有向图,比如 fromNode -> toNode。我想计算“toNode”上的总传入连接,包括 1 跳或 2 跳连接。
例如:如果有一个节点 Z 使得 X 连接 Z 并且 Z 连接 Y,则存在从节点 X 到节点 Y 的两跳连接。
解决方案
我认为您可以使用 aggregateMessages() 两次。
第一步,收集每个节点的 inDegrees,并存储它们。
第二步,收集节点中的inDegrees信息到最终节点。
或者,您可以先使用 outerJoinVertices(),例如:
yourGraph = followerGraph.outerJoinVertices(
yourGraph.ops().inDegrees(),
new setDegreesMsg()//use the function to combine inDegrees info with yourGraph
);
然后,使用 aggregateMessages() 收集邻居的 inDegrees 信息,例如:
degrees:RDD[(VertexId, Int)] = yourGraph.aggregateMessages(
new getInfoSendMsg(),
new getInfoMergeMsg()
);
推荐阅读
- c# - 我的 Unity 场景丢失了,但我还有脚本
- python-3.x - 尝试通过python脚本在postgresql中插入行时在“I”处或附近出现语法错误
- java - 使用 AdMob 加载时查看速度很慢
- python - 重命名写入的 csv 文件 pyspark
- javascript - 如何在多个控制器中使用 if else 条件而无需再次重写
- python - How is Python able to recognize which method is assigned to two different class methods that have the same name
- java - 使用 Spark 从 HDFS 到 Oracle BLOB 的 CSV 文件
- javascript - 无论在调用者上配置 catch 子句,都承诺拒绝
- jenkins - HTTP ERROR 404 Jenkins 仅提供此域上的静态文件
- java - 在 ImageView 中显示来自 MySQL 的原始 PNG