Closed bithw1 closed 5 years ago
Hi @bithw1 ,
I analyzed the code and IMO the problem is a misuse of optionals rather than Spark code. If you want to mark a value as missing, you should use None
instead of Some(null)
. Some
type by itself tells that Some(thing) exists and you can freely call the functions on the underlying object. null
is a little bit contradictory to Some and the engine tries to apply a computation on it which obviously leads to a NPE.
Instead you can:
use Option
if you know that you'll always have some value (null or not null). It will either return Some(...) if the underlying value is not null or None in the opposite.
Option(map1.get(v).get)
use getOrElse(null)
to return directly the value or null
if the value is missing
map1.get(v).getOrElse(null)
Best regards, Bartosz.
Thanks @bartosz25 . I agree that I have misused Option as I didn't realize I was actually returning an Option instead of the real with Map.get in the evaluate method. But, I remembered that it works for you to return Some(null) in the evaluate method?
In fact, the function from the post returns a TreeMap[Long, String]()
that is held inside MutableAggregationBuffer
at the index 0. And the map is defined in the initialize
method and hence it's never an optional nor null.
Best regards, Bartosz.
thanks, @bartosz25
Hi @bartosz25 , I post the code here, it is to get the max digits given the english word:
The test case code is as follows:
It will throw NPE when I run it.