问题
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