如何在Hive中将字符串转换为数组?

7

我正在使用Hive 1.1

 hive> select country from releases limit 1;
 OK
 ["us","ca","fr"]

目前,在Hive中,国家是字符串类型。如何将其转换为Array [String]?

我尝试了以下操作,但出现错误:

 hive> select country, cast(country as Array[String]) from releases limit 1;
 FAILED: ParseException line 1:48 cannot recognize input near 'Array' '[' 'String' in primitive type specification

有人可以帮我进行类型转换吗?

2个回答

10
hive> with releases as (select '["us","ca","fr"]' as country)
    > select  split(regexp_extract(country,'^\\["(.*)\\"]$',1),'","')
    > from    releases
    > ;
OK
_c0
["us","ca","fr"]

0
没有使用regexp_extract的方法
SELECT country, split(substr(country, 3, length(country) - 4),'","') AS arr FROM releases LIMIT 1;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接