码迷,mamicode.com
首页 > 其他好文 > 详细

spark自定义udf输入类型为array报错

时间:2018-03-07 17:34:38      阅读:844      评论:0      收藏:0      [点我收藏+]

标签:contains   pre   定义   自定义   user   数组   nbsp   div   spark   

定义udf如下

val list2string = udf { (style: Array[String], num: Array[Long]) =>
   style.zip(num).map(t => t._1 + ":" + t._2).mkString("<br>")
}

输入为两个数组,输出为string

 

报错如下

Caused by: java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofRef cannot be cast to [Ljava.lang.String;

 

打印输入字段类型

root

 |-- user_no: long (nullable = true)

 |-- style_list: array (nullable = true)

 |    |-- element: string (containsNull = true)

 |-- styleNum_list: array (nullable = true)

 |    |-- element: long (containsNull = true)

 

解决办法

更改udf输入为seq

val list2string = udf { (style: Seq[String], num: Seq[Long]) =>
   style.zip(num).map(t => t._1 + ":" + t._2).mkString("<br>")
}

 

spark自定义udf输入类型为array报错

标签:contains   pre   定义   自定义   user   数组   nbsp   div   spark   

原文地址:https://www.cnblogs.com/OS-BigData/p/8523607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!