Github user drewrobb commented on a diff in the pull request: https://github.com/apache/spark/pull/23062#discussion_r234853788 --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/ScalaReflectionSuite.scala --- @@ -109,6 +109,35 @@ object TestingUDT { } } +/** An example derived from Twitter/Scrooge codegen for thrift */ +object ScroogeLikeExample { + def apply(x: Int): ScroogeLikeExample = new Immutable(x) + + def unapply(_item: ScroogeLikeExample): Option[Int] = Some(_item.x) + + class Immutable(val x: Int) extends ScroogeLikeExample +} + +trait ScroogeLikeExample extends Product1[Int] with Serializable { + import ScroogeLikeExample._ + + def x: Int + + override def _1: Int = x + + def copy(x: Int = this.x): ScroogeLikeExample = new Immutable(x) + + override def canEqual(other: Any): Boolean = other.isInstanceOf[ScroogeLikeExample] + + private def _equals(x: ScroogeLikeExample, y: ScroogeLikeExample): Boolean = + x.productArity == y.productArity && --- End diff -- My previous answer was not complete. `Product1` is also necessary so that the implicit `Encoders.product[T <: Product : TypeTag]` will work with this class, if omitted the DatasetSuite test will not compile: ``` [error] /home/drew/spark/sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala:1577: value toDS is not a member of Seq[org.apache.spark.sql.catalyst.ScroogeLikeExample] [error] val ds = data.toDS ``` I could add some new encoder, but I think that might be worse as the goal of this PR is for Scrooge classes to work with the provided implicit encoders.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org