我们如何在hive中将字符串转换为数组?

时间:2017-08-30 16:52:23

标签: hadoop hive

我正在使用hive 1.1

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

现在,country是hive中的string类型。如何将其转换为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

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

1 个答案:

答案 0 :(得分:0)

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