例如,以用戶和產品型號爲二分圖,我們不妨做到以下幾點:
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
如果你的頂點包含相同類型的,爲什麼不'聯盟()'兩個頂點RDD的,並提交您的圖形? –
我不確定這是否是您要查找的內容,但是您可以聯合()兩個具有頂點的RDD(注意您需要唯一的VertexId),然後創建連接購物者頂點和產品頂點的邊。如果你願意,你也可以通過它們的'VertexId'連接兩個圖形(或圖形和頂點的RDD)。除非您提供更多詳細信息,否則很難說出最適合您的是什麼。 – lpiepiora