在运行与转换 RDD 时 protobuf 字段的序列化相关的 Spark 作业时,我看到错误。
com.esotericsoftware.kryo.KryoException:java.lang.UnsupportedOperationException 序列化跟踪: otherAuthors_ (com.thomsonreuters.kraken.medusa.dbor.proto.Book$DBBooks)
错误似乎是在此时创建的:
val booksPerTier: Iterable[(TimeTier, RDD[DBBooks])] = allTiers.map {
tier => (tier, books.filter(b => isInTier(endOfInterval, tier, b) && !isBookPublished(o)).mapPartitions( it =>
it.map{ord =>
(ord.getAuthor, ord.getPublisherName, getGenre(ord.getSourceCountry))}))
}
val averagesPerAuthor = booksPerTier.flatMap { case (tier, opt) =>
opt.map(o => (tier, o._1, PublisherCompanyComparison, o._3)).countByValue()
}
val averagesPerPublisher = booksPerTier.flatMap { case (tier, opt) =>
opt.map(o => (tier, o._1, PublisherComparison(o._2), o._3)).countByValue()
}
该字段是 protobuf 中指定的列表,如下所示:
otherAuthors_ = java.util.Collections.emptyList()
正如您所看到的,代码实际上并未利用 Book Protobuf 中的该字段,尽管它仍在通过网络传输。
有人对此有任何建议吗?
最佳答案
好吧,老问题,但这是给后代的答案。默认的 kryo 序列化器不能很好地处理某些集合。有一个第三方库可以帮助解决这个问题:kryo-serializers
在您的情况下,您可能需要在创建 Spark 配置时提供自定义 kryo 注册器:
val conf = new SparkConf()
conf.set("spark.kryo.registrator", "MyKryoRegistrator")
在您的注册器中进行所需的自定义注册:
class MyKryoRegistrator extends KryoRegistrator {
override def registerClasses(kryo: Kryo) {
kryo.register( Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer() );
// Probably should use proto serializer for your proto classes
kryo.register( Book.class, new ProtobufSerializer() );
}
}
关于scala - Spark、Kryo ProtoBuf 字段的序列化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38345362/