在GraphX中从RDD [Long,Long,ED]构造RDD [Edge [ED]]

时间:2018-05-07 11:58:09

标签: scala apache-spark rdd spark-graphx

我现在正试图从RDD[Edge[String]]构建RDD[(Long,Long,String)] 我看过Edge的src代码,它的参数为Edge(VertexId,VertexId,ED),所以我想如果我有RDD[(Long,Long,String)]我可以将其转换为RDD[Edge[String]]

我的代码是

val c:RDD[(String, String)] = something
val s:RDD[(String, String)] = something
val edgeRDD: RDD[Edge[String]] = c
        .join(s).map({
            case (num: String, (src: String, dst: String)) 
                => (src.toLong, dst.toLong, expRelation)
        }
    ) 

但最后我收到了type mismatch错误

[error]  found   : (Long, Long, String)
[error]  required: org.apache.spark.graphx.Edge[String]
[error]                     => (src.toLong, dst.toLong, expRelation)
[error]                        ^

所以我想知道是否有办法直接从RDD[Edge[ED]]构建RDD[(Long,Long,ED)]

1 个答案:

答案 0 :(得分:0)

您的函数未返回Edge [String]。将返回类型更改为

Edge(src.toLong, dst.toLong, expRelation)

代码:

val c:RDD[(String, String)] = something
val s:RDD[(String, String)] = something
val edgeRDD: RDD[Edge[String]] = c
        .join(s).map({
            case (num: String, (src: String, dst: String)) 
                => Edge(src.toLong, dst.toLong, expRelation)
        }
    )