定义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>")
}