对于GraphX,我如何将对象数组转换为边数组

时间:2016-04-29 12:28:20

标签: scala apache-spark spark-graphx

我有一个像这样的对象数组

 edges: Array[Array[(Long, Long, String)]] = Array(Array((-209215114,197853780,Investor), (-209215114,-322475625,Investor), ...

我希望将其转换为Edge数组以传递给Graph构建器。这是我正在使用的:

 val eRDD: RDD[Edge[(VertexId, VertexId, String)]] = edges.map(x => Edge(x(0), x(1), x(2)))

我收到以下错误:

<console>:107: error: type mismatch;
found   : (Long, Long, String)
required: org.apache.spark.graphx.VertexId
(which expands to)  Long
   val eRDD: RDD[Edge[(VertexId, VertexId, String)]] = edges.map(x => Edge(x(0), x(1), x(2)))

1 个答案:

答案 0 :(得分:2)

您的类型定义错误。要么:

val eRDD: RDD[Edge[String]] = edges.map(x => Edge(x(0), x(1), x(2)))

或只是这样做:

val eRDD = edges.map(x => Edge(x(0), x(1), x(2)))

让Scala为你推断出类型。