蜂巢-如何将数组转换为字符串? [英] Hive - How to cast array to string?

查看:106
本文介绍了蜂巢-如何将数组转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将包含逗号分隔数组的列强制转换为Hive中的字符串.

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

我收到以下错误

行:1-失败:SemanticException [错误10081]:SELECT子句之外不支持UDTF,也不嵌套在表达式中

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

推荐答案

爆炸函数将数组爆炸为多行.返回具有单列(col)的行集,该数组中的每个元素一行.

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.

您将需要concat_ws函数将逗号分隔的数组值连接为String.

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

功能:concat_ws(字符串SEP,数组)

function: concat_ws(string SEP, array)

请参阅: https://cwiki.apache.org/confluence/display/Hive/LanguageManual + UDF

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

concat_ws将返回由数组值构造的逗号分隔的字符串.

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

这篇关于蜂巢-如何将数组转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆