最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Map<String, String> to Map<String, BigDecimal> in spark - Stack Overflow

programmeradmin4浏览0评论

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>

发布评论

评论列表(0)

  1. 暂无评论