Converting Array of Strings in Spark to byte array and retrieving it back using UDFs

后端 未结 1 884
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 02:52

I am trying to convert Array of Strings to byte-array in Spark and re-converting the byte-array to Array of Strings.

However, I am not getting the String array back

相关标签:
1条回答
  • 2021-01-17 03:15

    you take a list of strings and and treat it as a single object and at the conversion back you treat it as if was just a string- if you want a single string back you also need to convert the list to a string:

    val convertToByteArray = udf((map: Seq[String]) => mapper.writeValueAsBytes(map.mkString("[",",","]")))
    
    0 讨论(0)
提交回复
热议问题