Spark GraphX - 实现FoFoF

时间:2017-05-29 11:49:45

标签: apache-spark spark-dataframe spark-graphx

如何在Spark GraphX中找到FoFoF?

在Cypher我有查询:

MATCH (f:Friend)-[:friend_of]-(Friend)-[:friend_of]-(c:Friend)
WHERE c.name STARTS WITH "T"
RETURN f.name AS Friend1 , c2.name as Friend2

here

的另一个例子
MATCH (john {name: 'John'})-[:friend]->()-[:friend]->(fof)
RETURN john.name, fof.name

基本上它的剂量:此查询在返回'John'和找到的任何朋友之前找到一个名为'John'和'John'的朋友(虽然不是他的直接朋友)

  • Spark GraphX的替代实施是什么?
  • 如何将此查询实现为Spark GraphX?

这是Spark Graph X的示例:

// Create an RDD for the vertices
val users: RDD[(VertexId, (String, String))] =
  sc.parallelize(Array((3L, ("rxin", "student")), (7L, ("jgonzal", "postdoc")),
                       (5L, ("franklin", "prof")), (2L, ("istoica", "prof")),
                       (4L, ("peter", "student"))))

// Create an RDD for edges
val relationships: RDD[Edge[String]] =
  sc.parallelize(Array(Edge(3L, 7L, "friend_of"),   Edge(5L, 3L, "friend_of"),
                       Edge(2L, 5L, "friend_of"),   Edge(5L, 7L, "friend_of"),
                       Edge(4L, 0L, "friend_of"),   Edge(5L, 0L, "friend_of")))

// Define a default user in case there are relationship with missing user
val defaultUser = ("John Doe", "Missing")

// Build the initial Graph
val graph = Graph(users, relationships, defaultUser)


// Where do we go, Where do we go now..?!

我看到的GraphX中的所有示例都是相同的概念Node->Rel->Node。但如何做Node->Rel->Node->Rel->Node

0 个答案:

没有答案