我在spark custom kryo encoder not providing schema for UDF中已经列出了火花问题,但现在创建了一个最小样本: https://gist.github.com/geoHeil/dc9cfb8eca5c06fca01fc9fc03431b2f
class SomeOtherClass(foo: Int)
case class FooWithSomeOtherClass(a: Int, b: String, bar: SomeOtherClass)
case class FooWithoutOtherClass(a: Int, b: String, bar: Int)
case class Foo(a: Int)
implicit val someOtherClassEncoder: Encoder[SomeOtherClass] = Encoders.kryo[SomeOtherClass]
val df2 = Seq(FooWithSomeOtherClass(1, "one", new SomeOtherClass(4))).toDS
val df3 = Seq(FooWithoutOtherClass(1, "one", 1), FooWithoutOtherClass(2, "two", 2)).toDS
val df4 = df3.map(d => FooWithSomeOtherClass(d.a, d.b, new SomeOtherClass(d.bar)))
这里,即使createDataSet
语句由于
java.lang.UnsupportedOperationException: No Encoder found for SomeOtherClass
- field (class: "SomeOtherClass", name: "bar")
- root class: "FooWithSomeOtherClass"
为什么编码器不在范围内或至少不在合适的范围内?
另外,尝试指定一个显式编码器,如:
df3.map(d => {FooWithSomeOtherClass(d.a, d.b, new SomeOtherClass(d.bar))}, (Int, String, Encoders.kryo[SomeOtherClass]))
不起作用。
答案 0 :(得分:3)
这是因为你应该在整个序列化堆栈中使用Kryo编码器,这意味着你的顶级对象应该有一个Kryo编码器。以下在本地Spark shell上成功运行(您感兴趣的更改位于第一行):
$('.js-dropdown-toggle').on('click', function(e) {
e.preventDefault();
var $dropdownContent = $('.dropdown-content');
$dropdownContent.removeClass('visible-dropdown');
$(this).next('.dropdown-content').toggleClass('visible-dropdown');
});