aalexandrov commented on pull request #11895:
URL: https://github.com/apache/flink/pull/11895#issuecomment-808167845


   Just to clarify - after building a scala-shell with the changes from this 
PR, and testing as follows:
   
   1. Start scala-shell:
   
   ```bash
   bin/start-scala-shell.sh local
   ```
   
   2. Run 
   
   ```scala
   scala> case class Pair(x: Int, y: Int)
   defined class Pair
   
   scala> benv.fromElements(1,2,3).map(x => Pair(x,x)).collect()
   java.lang.IllegalArgumentException: requirement failed:
   The class Pair is an instance class, meaning it is not a member of a
   toplevel object, or of an object contained in a toplevel object,
   therefore it requires an outer instance to be instantiated, but we don't 
have a
   reference to the outer instance. Please consider changing the outer class to 
an object.
   
     at scala.Predef$.require(Predef.scala:277)
     at 
org.apache.flink.api.scala.typeutils.ScalaCaseClassSerializer$.lookupConstructor(ScalaCaseClassSerializer.scala:97)
     at 
org.apache.flink.api.scala.typeutils.ScalaCaseClassSerializer.<init>(ScalaCaseClassSerializer.scala:46)
     ... 70 elided
   ```
   
   The problem is that with `-Yrepl-class-based` enabled, UDTs (such as case 
classes) are defined within a nested class, and as such cannot be easily 
serialized (the `ScalaCaseClassSerializer` invoked by the 
`org.apache.flink.api.scala.createTypeInformation` throws a very detailed error 
explaining this).
   
   I am not sure what were the use-cases that lead the Scala team (and Spark) 
to adopt `-Yrepl-class-based` over the traditional object-based wrapping - it 
seems that nesting objects in objects is more robust w.r.t. serialization. 
   
   FYI in Scala 2.13 the default is class-based and it needs to be explicitly 
disabled with `-Yrepl-class-based:false`.
   
   @aljoscha / @zjffdu: do you know any particular scenarios where object-based 
REPL is problematic?
     


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to