GraphX​​:给定一个VertexID获得所有连接Vertexs [英] GraphX: Given one VertexID get all connected Vertexs

查看:501
本文介绍了GraphX​​:给定一个VertexID获得所有连接Vertexs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我有一个图,在GraphX​​图形的特定顶点的ID。

So basically I have a graph and an ID of a specific vertex in a graph in GraphX.

由于VertexID,我如何才能所有直接连接的顶点到一个顶点? (IE,距离酒店只有一个边缘)。

Given that VertexID, how do I get all directly connected vertexes to that one vertex? (IE, only one edge away).

感谢您

推荐答案

让我们假设你想找到直接连接的所有用户富兰克林( VertexId 5L)使用的例子图从 GraphX​​编程指南。最简单也可能是最有效的方法是使用 collectNeighborIds / graph.collectNeighbors 然后按查找

Lets assume you want to find all users directly connected to "franklin" (VertexId 5L) using example graph from the GraphX Programming Guide. The simplest and probably the most efficient approach is to use collectNeighborIds / graph.collectNeighbors followed by lookup:

import org.apache.spark.graphx.EdgeDirection

val direction: EdgeDirection = ???  // In, Out ...
graph.collectNeighborIds(direction).lookup(5L)

另一种方法是使用三胞胎过滤器结果:

// "franklin" is source
graph.triplets.collect {
  case t if t.srcId == 5L => t.dstId
}

当然,你可以添加其他方向,并通过如 srcAttr dstAttr 更多信息或 vertexAttr 。如果preFER保持完整的三重你可以替换收集过滤。不过,如果你需要单边/顶点查找Spark是最有可能不适合这个职位的最佳工具。

Of course you can add other direction and pass additional information like srcAttr, dstAttr or vertexAttr. If you prefer to keep complete triplet you can replace collect with filter. Nevertheless if you need single edge / vertex lookups Spark is most likely not the best tool for the job.

这篇关于GraphX​​:给定一个VertexID获得所有连接Vertexs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆