Abou Haydar Elias created ZEPPELIN-747: ------------------------------------------
Summary: Companion object in Scala isn't associating itself with case class Key: ZEPPELIN-747 URL: https://issues.apache.org/jira/browse/ZEPPELIN-747 Project: Zeppelin Issue Type: Improvement Reporter: Abou Haydar Elias Companion object in Scala isn't associating itself with case class and :paste mode isn't available to remedy to this problem. The following code will generate the error concerning companion object association with it's case class. {code} import org.apache.spark.util.StatCounter class NAStatCounter extends Serializable { val stats: StatCounter = new StatCounter() var missing: Long = 0 def add(x: Double): NAStatCounter = { if (java.lang.Double.isNaN(x)) { missing += 1 } else { stats.merge(x) } this } def merge(other: NAStatCounter): NAStatCounter = { stats.merge(other.stats) missing += other.missing this } override def toString = { "stats: " + stats.toString + " NaN: " + missing } } object NAStatCounter extends Serializable { def apply(x: Double) = new NAStatCounter().add(x) } {code} To solve this error, the scala/spark repl support the `paste mode` as described [here|https://www.safaribooksonline.com/library/view/scala-cookbook/9781449340292/ch14s03.html]. As for now, the only solution is to attach the class and object definition on the same line using a semi-colon as followed : {code} import org.apache.spark.util.StatCounter class NAStatCounter extends Serializable { val stats: StatCounter = new StatCounter() var missing: Long = 0 def add(x: Double): NAStatCounter = { if (java.lang.Double.isNaN(x)) { missing += 1 } else { stats.merge(x) } this } def merge(other: NAStatCounter): NAStatCounter = { stats.merge(other.stats) missing += other.missing this } override def toString = { "stats: " + stats.toString + " NaN: " + missing } }; object NAStatCounter extends Serializable { def apply(x: Double) = new NAStatCounter().add(x) } {code} So what do you think ? Is it possible to support this paste mode ? -- This message was sent by Atlassian JIRA (v6.3.4#6332)