Search code examples
scalahiveudf

How to return null in hive udf in scala?


I am working on a Hive UDF in Scala

class MyUDF extends UDF {
    def func(a: Double): Double {
        if (cond){ how to return null in this case? }
        else {some double}
    }
}

I tried null.asInstanceOf[Double] but this gives the output as 0. I need a NULL output in hive instead.

Thanks.


Solution

  • A Scala Double cannot be null. Can you change the interface to return a java.lang.Double?