我在scala的spark 1.6.2中实现了Kryo序列化。我得到"org.apache.spark.SparkException: Task not serializable"
以下getdate方法。
我在地图转换中使用下面的getdate函数来获取日期。
def getdate(s: String,format_ts:String): Option[Date] = s match {
case "" => null
case _ =>
val format = new SimpleDateFormat(format_ts)
Try(new Date(format.parse(s).getTime)).toOption
}
但是当我在date列中插入null时,它工作正常。
有人可以帮助我什么类需要成为kryo序列化的一部分?谢谢
我对火花中的Kryo序列化并不熟悉。但根据我的经验,SimpleDateFormat不能用spark来序列化。 SimpleDateFormat类在java中实现Serializable。但是当使用spark时它不可序列化(当它解析为hadoop的Executor程序时,该类无法序列化。)我得到了同样的错误。您可以使用LocalDate而不是使用SimpleDateFormat来完成任务。对我来说,LocalDate在许多情况下都运行良好。