Performance of Spark Row Operation - grant-guo/Ideas GitHub Wiki

Try(row.getInt(index)) match {
    case Success(value) => ...
    case Failure(exception) => ...
}

or

if(row.isNullAt(index)) {
    ...
} else {
    ...
}

The second approach is much better than the first in terms of performance

In Spark API, if the value is null, Row.getInt(..), Row.getLong(...), Row.getDouble(...) throw NullPointerException. Instead, Row.getString(..) return null.