是我的代碼:APARCH火花,NotSerializableException:這裏org.apache.hadoop.io.Text
val bg = imageBundleRDD.first() //bg:[Text, BundleWritable]
val res= imageBundleRDD.map(data => {
val desBundle = colorToGray(bg._2) //lineA:NotSerializableException: org.apache.hadoop.io.Text
//val desBundle = colorToGray(data._2) //lineB:everything is ok
(data._1, desBundle)
})
println(res.count)
lineB順利,但LINEA表明:org.apache.spark.SparkException:作業已中止:任務不可序列:java.io.NotSerializableException:org.apache.hadoop.io.Text
我嘗試使用使用KRYO解決我的問題,但它似乎什麼也沒有發生變化:
import com.esotericsoftware.kryo.Kryo
import org.apache.spark.serializer.KryoRegistrator
class MyRegistrator extends KryoRegistrator {
override def registerClasses(kryo: Kryo) {
kryo.register(classOf[Text])
kryo.register(classOf[BundleWritable])
}
}
System.setProperty("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
System.setProperty("spark.kryo.registrator", "hequn.spark.reconstruction.MyRegistrator")
val sc = new SparkContext(...
謝謝!
Dup的看到http://stackoverflow.com/a/22594142/1586965 – samthebest
使用這個答案http://stackoverflow.com/a/25270600/1586965 – samthebest