如何在 Spark 中使用 Kryo 注册 InternalRow [英] How to register InternalRow with Kryo in Spark
问题描述
我想使用 Kryo 序列化运行 Spark.因此我设置了 spark.serializer=org.apache.spark.serializer.KryoSerializer
和 spark.kryo.registrationRequired=true
I want to run Spark with Kryo serialisation. Therefore I set spark.serializer=org.apache.spark.serializer.KryoSerializer
and spark.kryo.registrationRequired=true
然后当我运行我的代码时出现错误:
When I then run my code I get the error:
类未注册:org.apache.spark.sql.catalyst.InternalRow[]
Class is not registered: org.apache.spark.sql.catalyst.InternalRow[]
根据这篇文章,我使用了
sc.getConf.registerKryoClasses(Array( classOf[ org.apache.spark.sql.catalyst.InternalRow[_] ] ))
但是错误是:
org.apache.spark.sql.catalyst.InternalRow 不带类型参数
org.apache.spark.sql.catalyst.InternalRow does not take type parameters
推荐答案
你应该使用一个外部类作为
you should use an external class as
class MyRegistrator extends KryoRegistrator {
override def registerClasses(kryo: Kryo) {
kryo.register(classOf[Array[org.apache.spark.sql.catalyst.InternalRow]])
}
}
来源:http://spark.apache.org/docs/0.6.0/tuning.html
或者如果你想注册你的火花班
Or if you want to register in your spark class
val cls: Class[Array[InternalRow]] = classOf[Array[org.apache.spark.sql.catalyst.InternalRow]]
spark.sparkContext.getConf.registerKryoClasses(Array(cls))
我使用第一个并且运行良好,我还没有测试第二个.
I use the first one and works perfectly, I haven't tested the second one.
这篇关于如何在 Spark 中使用 Kryo 注册 InternalRow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!