【发布时间】:2015-10-25 20:03:30
【问题描述】:
我很难从键来自不同 RDD 的 RDD 中查找值。 我需要将 topsuperhero array[Int] 的 RDD 转换为纯字符串,然后我可以传递给 namesmap.lookup rdd。
如何将 [Int] 数组转换为纯字符串?我需要写一个函数吗?
val names = sc.textFile("C:\\Users\\kalit_000\\Desktop\\udemy_spark\\marvelnames.txt")
val namemap = names.map(x => x.split(" ")).map(x => (x(0),x(1)))
val graph = sc.textFile("C:\\Users\\kalit_000\\Desktop\\udemy_spark\\marvelgraph.txt")
val graphmap = graph.map(x => x.split(" ")).map(x => (x(0).toInt,(x.length -1).toInt))
val totalfirendsBycharacter = graphmap.mapValues(x => (x)).reduceByKey((x,y) => x+y)
val topsuperhero = totalfirendsBycharacter.sortBy(_._2,false).take(1)
错误: topsuperhero 是 array[Int],我需要将其转换为纯字符串,我该如何实现?
namemap.lookup(topsuperhero.map(x => x._1)).foreach(println)
【问题讨论】:
标签: scala apache-spark