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]
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
. 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
). It's a bit like a promise of a collection Int
. You have to poll the collection out before you mkString
with the results.
Call .collect()
on the RDD[Int]
before you perform mkString
.
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.