即使在conf中注册了类,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: 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)
weiyi961013 回答:即使在conf中注册了类,Kryo序列化也没有注册

在注册了两个用例之后,它就起作用了:

.registerKryoClasses(
      Array(classOf[Person],classOf[Array[Person]])
    )
本文链接:https://www.f2er.com/3009877.html

大家都在问