I have implemented a method that is supposed to convert an array of strings into a single string. But getting an exception when using it with UDF and applying the UDF to a column: val concatUdf = udf(convertArray)
java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofRef cannot be cast to [Ljava.lang.String;
What should be improved in my current implementation in order to return valid String? I'm new to Scala and probably this is not the most elegant solution.
def convertArray: Array[String] => String =
(strings: Array[String]) => {
Option(strings) match {
case Some(arr) => strings.mkString(", ")
case Some(Array()) => ""
case None => ""
}
}