Spark Scala - Joining two arrays by VertexID

2019-09-19 22:20发布

问题:

I have 2 arrays in the following format

scala> cPV.take(5)
res18: Array[(org.apache.spark.graphx.VertexId, String)] = Array((-496366541,7804412), (183389035,11517829), (1300761459,36164965), (978932066,32135154), (370291237,40355685))

scala> fC.take(5)
res19: Array[(org.apache.spark.graphx.VertexId, Int)] = Array((386253628,1), (-1141923433,1), (1871855296,7), (1938255756,1), (-749015657,5))

I need to join them to get into the format - Array[(org.apache.spark.graphx.VertexId, Int, String)]

I have tried .join() but it throws the following error

val mVP = fC.join(cPV)
<console>:64: error: value join is not a member of Array[(org.apache.spark.graphx.VertexId, Int)]
       val mVP = fC.join(cPV)

I also tried this and it didn't work.

回答1:

I tried the following and it worked

val fCRDD = sc.parallelize(fC)
scala> val mVP = fCRDD.join(cPV)
mVP: org.apache.spark.rdd.RDD[(org.apache.spark.graphx.VertexId, (Int, String))] = MapPartitionsRDD[106] at join at <console>:67

scala> mVP.take(5)
res21: Array[(org.apache.spark.graphx.VertexId, (Int, String))] = Array((-891966589,(4,D)), (166544732,(74,V)), (1871855296,(7,LG)), (1416009424,(6,Dck)), (-241988197,(4,L)))

Sorry, Noob here - I should have tried this before posting a question here.