Scala 即使在conf中注册了类,Kryo序列化也没有注册
我创建了一个类Person并注册了它,但在运行时,它显示了未注册的类。为什么会这样显示Scala 即使在conf中注册了类,Kryo序列化也没有注册,scala,apache-spark,serialization,kryo,Scala,Apache Spark,Serialization,Kryo,我创建了一个类Person并注册了它,但在运行时,它显示了未注册的类。为什么会这样显示 Exception in thread "main" org.apache.spark.SparkException: Job aborted due to stage failure: Failed to serialize task 0, not attempting to retry it. Exception during serialization: java.io.IOException: jav
Exception in thread "main" org.apache.spark.SparkException: Job aborted due to stage failure: Failed to serialize task 0, not attempting to retry it. Exception during serialization: java.io.IOException: java.lang.IllegalArgumentException: Class is not registered: KyroExample$Person[]
Note: To register this class use: kryo.register(KyroExample$Person[].class);
以下是示例代码:
val conf = new SparkConf().setAppName("kyroExample").setMaster("local")
conf.set("spark.serializer","org.apache.spark.serializer.KryoSerializer")
conf.registerKryoClasses(Array(classOf[Person],classOf[String])) //registered the class
conf.set("spark.kryo.registrationRequired", "true")
val sparkContext = new SparkContext(conf)
case class Person(name:String, age:Int) //this is the class
val personList: immutable.Seq[Person] = (1 to 100000).map(value=> Person(value+"",value))
val rdd: RDD[Person] = sparkContext.parallelize(personList)
val evenAge: RDD[Person] = rdd.filter(_.age %2 ==0)
evenAge.persist(StorageLevel.MEMORY_ONLY_SER)
evenAge.count()
evenAge.persist(StorageLevel.MEMORY_ONLY_SER)
evenAge.count()
Thread.sleep(200000)
它在注册两个用例后都起作用:
.registerKryoClasses(
Array(classOf[Person],classOf[Array[Person]])
)
如果不发生这种情况,请尝试此.set(“spark.kryo.registor”,classOf[kryoregistor].getName)