You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Michael Malak <mi...@yahoo.com> on 2014/05/13 02:02:35 UTC
Serializable different behavior Spark Shell vs. Scala Shell
I'm seeing different Serializable behavior in Spark Shell vs. Scala Shell. In the Spark Shell, equals() fails when I use the canonical equals() pattern of match{}, but works when I subsitute with isInstanceOf[]. I am using Spark 0.9.0/Scala 2.10.3.
Is this a bug?
Spark Shell (equals uses match{})
=================================
class C(val s:String) extends Serializable {
override def equals(o: Any) = o match {
case that: C => that.s == s
case _ => false
}
}
val x = new C("a")
val bos = new java.io.ByteArrayOutputStream()
val out = new java.io.ObjectOutputStream(bos)
out.writeObject(x);
val b = bos.toByteArray();
out.close
bos.close
val y = new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(b)).readObject().asInstanceOf[C]
x.equals(y)
res: Boolean = false
Spark Shell (equals uses isInstanceOf[])
========================================
class C(val s:String) extends Serializable {
override def equals(o: Any) = if (o.isInstanceOf[C]) (o.asInstanceOf[C].s == s) else false
}
val x = new C("a")
val bos = new java.io.ByteArrayOutputStream()
val out = new java.io.ObjectOutputStream(bos)
out.writeObject(x);
val b = bos.toByteArray();
out.close
bos.close
val y = new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(b)).readObject().asInstanceOf[C]
x.equals(y)
res: Boolean = true
Scala Shell (equals uses match{})
=================================
class C(val s:String) extends Serializable {
override def equals(o: Any) = o match {
case that: C => that.s == s
case _ => false
}
}
val x = new C("a")
val bos = new java.io.ByteArrayOutputStream()
val out = new java.io.ObjectOutputStream(bos)
out.writeObject(x);
val b = bos.toByteArray();
out.close
bos.close
val y = new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(b)).readObject().asInstanceOf[C]
x.equals(y)
res: Boolean = true