问题描述
我可以使用 vertexRDD
和 edgeRDD
通过GraphX API,没有问题那里建立一个图。即:
I am able to build a graph using a vertexRDD
and an edgeRDD
via the GraphX API, no problem there. i.e.:
val graph: Graph[(String, Int), Int] = Graph(vertexRDD, edgeRDD)
不过,我不知道从哪里开始,如果我想使用两个单独的vertexRDD的,而不只是一个(二部图)。前例如,含有购物者和产品的顶点的曲线图。
However, I don't know where to start if I want to use two separate vertexRDD's instead of just one (a bipartite graph). Fore example, a graph containing shopper and product vertices.
我的问题是广泛,所以我没想到一个详细的例子,而是暗示或在正确的方向轻推。任何建议将是多少AP preciated。
My question is broad so I'm not expecting a detailed example, but rather a hint or nudge in the right direction. Any suggestions would be much appreciated.
推荐答案
例如,以用户和产品型号为二分图我们可以做到以下几点:
For example to model users and products as a bipartite graph we might do the following:
trait VertexProperty
case class UserProperty(val name: String) extends VertexProperty
case class ProductProperty(val name: String,
val price: Double) extends VertexProperty
val users: RDD[(VertexId, VertexProperty)] = sc.parallelize(Seq(
(1L, UserProperty("user1")), (2L, UserProperty("user2"))))
val products: RDD[(VertexId, VertexProperty)] = sc.parallelize(Seq(
(1001L, ProductProperty("foo", 1.00)), (1002L, ProductProperty("bar", 3.99))))
val vertices = VertexRDD(users ++ products)
// The graph might then have the type:
val graph: Graph[VertexProperty, String] = null
这篇关于如何创建GraphX二分图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!