我正在从目标文件中读取以下结构:
(String, CompactBuffer(person1, person2, person3 ...) )
如果我试着这样读:
val input = sc.objectFile[(String, ListBuffer[Person])]("inputFile.txt")
val myData = input.map { t =>
val myList = t._2
for (p <- myList) {
println(p.toString())
}
t
}
我收到以下错误:
java.lang.ClassCastException: org.apache.spark.util.collection.CompactBuffer cannot be cast to scala.collection.mutable.ListBuffer
但是,在读取objectFile时我不能使用CompactBuffer:
val input = sc.objectFile[(String, CompactBuffer[Person])]("inputFile.txt")
Eclipse会告诉我:
class CompactBuffer in package collection cannot be accessed in package
org.apache.spark.util.collection
那么如何从objectFile中读取这样的CompactBuffer?谢谢!
答案 0 :(得分:2)
查看https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/util/collection/CompactBuffer.scala,我们可以看到CompactBuffer
是Seq的子类,因此请尝试val input = sc.objectFile[(String, Seq[Person])]("inputFile.txt")