我遇到了麻烦,我在序列化中假设,在Spark repl。
我有以下代码段:
class Foobar (val a: Int, val b: Int) extends Serializable {
override def equals (other: Any): Boolean =
other match {
case that: Foobar =>
println("Comparison of similar objects")
this.a == that.a && this.b == that.b
case _ =>
println("Comparison of disparate objects")
false
}
override def toString = s"[$a:$b]"
}
如果我创建两个实例,一个(foo)在一个worker上,一个(bar)在驱动程序上:
val foo = sc.parallelize(Seq(1)).map(n => new Foobar(n, n)).collect.apply(0)
val bar = new Foobar(1, 1)
然后foo != bar
(和鲸鱼喷水“不同对象的比较”) - 然而
foo.getClass == bar.getClass
foo.a == bar.a
和foo.b == bar.b
有人可以解释为什么会这样吗?