我在 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) 在工作人员上,一个 (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
谁能解释为什么会这样?