简体   繁体   English

值mkString不是org.apache.spark.rdd.RDD [Int]的值

[英]value mkString is not a value of org.apache.spark.rdd.RDD[Int]

I changed this line: 我更改了这一行:

val ratedNum = rows.sortBy(- _._2).map{case (user , ratednum) => ratednum}.take(20).mkString("::")

to: 至:

val ratedNum = rows.sortBy(- _._2).map{case (user , ratednum) => ratednum}.mkString("::") 

But Eclipse is giving me an error hint: value mkString is not a value of org.apache.spark.rdd.RDD[Int] 但是Eclipse给了我一个错误提示: value mkString is not a value of org.apache.spark.rdd.RDD[Int]

What does this error mean? 这个错误是什么意思?

val ratedNum = rows.sortBy(- _._2).map{case (user , ratednum) => ratednum}

This returns an org.apache.spark.rdd.RDD[Int] which is not GenTraversableOnce . 这将返回不是GenTraversableOnceorg.apache.spark.rdd.RDD[Int] Although it has a lot of methods defined which makes it like a Scala collection of Int , it is not ( abstract class RDD[T] extends Serializable with Logging ). 尽管它定义了很多方法,使它像Int的Scala集合一样, 但不是abstract class RDD[T] extends Serializable with Logging )。 It's a bit like a promise of a collection Int . 这有点像Int集合的承诺。 You have to poll the collection out before you mkString with the results. 您必须先对集合进行轮询,然后mkString结果mkString

Call .collect() on the RDD[Int] before you perform mkString . 在执行mkString之前,请在RDD[Int]上调用.collect()

val ratedNum = rows.sortBy(- _._2).map{case (user , ratednum) => ratednum}.collect.mkString("::")

Or you can add an implicit conversion: 或者,您可以添加一个隐式转换:

implicit def toArray[T](rdd: RDD[T]) = rdd.collect()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM