【问题标题】:How to add extra attributies to vertices (that already have attributes) in a graph in Spark Graphx Scala?如何在 Spark Graphx Scala 的图中向顶点(已经有属性)添加额外的属性?
【发布时间】:2015-09-09 21:05:43
【问题描述】:

情况:

我在 Spark(在 scala 中)基于一些高音扬声器数据构建了一个图表,如下所示:

  • 每个顶点都有一个推文 id(Long) 和推文正文 (String)
  • 每条边都将源推文连接到转发推文

我的做法是从边文件中创建一个图形:

val followerGraph = GraphLoader.edgeListFile(sc, "C:\\Users\\...\\tweetGraphEdgesData.txt")

然后使用 outerJoinVertices 将属性添加到每个顶点

   val graph = followerGraph.outerJoinVertices(verticesData){
    case(uid,deg,Some(attrList))=>attrList
    case(uid,deg,None)=> Array.empty[String]
   }

问题:

现在我想将它连接到的边数附加到每个顶点(这基本上意味着它被转发了多少次)。我该怎么做?

【问题讨论】:

标签: scala twitter graph apache-spark spark-graphx


【解决方案1】:

用输出边的数量简单地连接顶点

graph.vertices.leftOuterJoin(graph.outDegrees)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多