如何将数组 转换为蜂巢中的字符串

问题描述 投票:0回答:1

我想将array<string>转换为蜂巢中的字符串。数组数据如下:

+-------------------------------------+--+
| NULL                                |
| ["Extension","Terms & Conditions"]  |
| ["Value (generic or item level)"]   |
+-------------------------------------+--+

我想收集数组值以将其转换为不带[""]的字符串,以便获得类似以下结果:

+-------------------------------------+--+
| NULL                                |
| Extension,Terms & Conditions        |
| Value (generic or item level)       |
+-------------------------------------+--+

以下查询:select concat_ws(',', col_name) as col_name from table_stg;提供了结果,但返回的NULL为空。我尝试了几种参考:

How can I convert array to string in hive sql?

Hive - How to cast array to string?

但未获得理想的结果。有什么方法可以得到理想的结果吗?

arrays string hive hiveql
1个回答
0
投票

参考Vamsi的评论,我设法做到了这一点,并想回答一下以供社区参考。

select case when col_name is NULL then NULL 
    else concat_ws(',',col_name) end from table_name;
© www.soinside.com 2019 - 2024. All rights reserved.