Search code examples
scalaapache-zeppelincase-class

Defining a case class in zeppelin fails


I am using zeppelin embedded in another application. The zeppelin version is 0.6.1-SNAPSHOT. Defining the below case class I get an error

case class GenRandInt(lb : Int, ub : Int)
{
 val rnd = new scala.util.Random
 def next() : Int = { lb + rnd.nextInt(ub) }
}

defined class GenRandInt 
<console>:40: error: not found: value lb
               def next() : Int = { lb + rnd.nextInt(ub) }

The code executes successfully in an IDE. What could be going wrong?


Solution

  • The problem was due to indentation.

    enter image description here

    Details

    scala> :paste // Entering paste mode (ctrl-D to finish)

    case class GenRandInt(lb : Int, ub : Int)
    {
     val rnd = new scala.util.Random
     def next(): Int = { lb + rnd.nextInt(ub) }
    }
    
    // Exiting paste mode, now interpreting.
    
    defined class GenRandInt
    
    scala>
    

    In scala, we can define case classes using that indentation. So I think it's the problem of spark interpreter in zepplin or maybe spark itself. (tested on scala 2.10.6, zeppelin 0.7.0-SNAPSHOT built with scala 2.10.6)