How to create a bipartite graph in GraphX

前端 未结 1 1292
别跟我提以往
别跟我提以往 2020-12-11 07:26

I am able to build a graph using a vertexRDD and an edgeRDD via the GraphX API, no problem there. i.e.:



        
相关标签:
1条回答
  • 2020-12-11 08:05

    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
    
    0 讨论(0)
提交回复
热议问题