Darshan Darshan - 2 months ago 15
Scala Question

Null check for Double/Int Value in Spark

I am new in Spark,
How can I check for for Null value in Double and Int value in scala or Spark.

Like for String We can do like this :

val value = (FirstString.isEmpty()) match {
case true => SecondString
case _ => FirstString
}


I searched for it a lot but i found only for String value. Can you please suggest me for other datatype as well.

Thanks in advance.

Answer

May be you can simply use Options. So like:

val d: Double = ...

val isNull = Option(d).isDefined

Or you can use pattern matching:

val d: Double = ...

Option(d) match {
  case Some(v) => use v
  case _ => you got Null
}
Comments