Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
861 views
in Technique[技术] by (71.8m points)

apache spark - How to create a bipartite graph in GraphX

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)

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...