Search code examples
scalaapache-sparkemramazon-emrapache-zeppelin

Zeppelin fails to check regex from z.input dynamic form


I'm having trouble with a scala apache notebook running on EMR. The following code runs fine in the notebook:

var d1 = "2016-12-26"
var datePattern = "[0-9]{4}-[0-9]{2}-[0-9]{2}".r
println(datePattern.findFirstIn(d1))

Returning

Some(2016-12-26)

So does the following:

var d1 = z.input("date (yyyy-mm-dd)", "12-25-2016")
println(d1)
println(d1.getClass)

Returning:

12-25-2017
class java.lang.String

But the following fails:

var d1 = z.input("date (yyyy-mm-dd)", "12-25-2016")
var datePattern = "[0-9]{4}-[0-9]{2}-[0-9]{2}".r
println(datePattern.findFirstIn(d1))

with no output or backtrack and only "ERROR" next to the play button.


Solution

  • This shall work

    var d1 = z.input("date (yyyy-mm-dd)", "2016-12-25").toString
    var datePattern = "[0-9]{4}-[0-9]{2}-[0-9]{2}".r
    println(datePattern.findFirstIn(d1))
    

    z.input define as this in ZeppelinContext

    public Object input(String name, Object defaultValue) {
      return gui.input(name, defaultValue);
    }
    

    It returns an Object, although the real class is String.