I got the below exception in java spark when trying to encode a pojo with a field of type Map<String, BigDecimal>
Caused by: .codehausmonspiler.CompileException: File 'generated.java', Line 622, Column 51: failed to compile: .codehausmonspiler.CompileException: File 'generated.java', Line 622, Column 51: A method named "toJavaBigDecimal" is not declared in any enclosing class nor any supertype, nor through a static import
So I wrote the below udf to convert a Map<String, String> to Map<String, BigDecimal>
UserDefinedFunction strMapToBigDecimalMap = udf((Map<String, String> s) -> {
Map<String, BigDecimal> s1 = new HashMap<>();
for (String key : s.keySet()) {
s1.put(key, new BigDecimal(s.get(key)));
}
return s1;
}, new MapType());
But this is returning the below exception. How do I resolve this?
scala.MatchError: null
Basically, I am looking for a udf which will convert Map<String, String> to Map<String, BigDecimal>