Hive - How to cast array to string?

匆匆过客 提交于 2021-02-08 10:13:00

问题


I'm trying to coerce a column containing a comma separated array to a string in Hive.

SELECT email_address, CAST(explode(GP_array AS STRING)) AS GP
FROM dm.TP

i get the following error

Line: 1 - FAILED: SemanticException [Error 10081]: UDTF's are not supported outside the SELECT clause, nor nested in expressions


回答1:


explode function Explodes an array to multiple rows. Returns a row-set with a single column (col), one row for each element from the array.

you would need concat_ws function to concatenate comma separated array values to String.

function: concat_ws(string SEP, array)

Refer to: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF

SELECT email_address, concat_ws(',', GP_array) AS GP FROM dm.TP

concat_ws will return the comma separated String constructed from Array values.



来源:https://stackoverflow.com/questions/52483400/hive-how-to-cast-array-to-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!