Hive str to array / regexp_extract

Posted 二十六画生的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hive str to array / regexp_extract相关的知识,希望对你有一定的参考价值。

with releases as (select '["us","ca","fr"]' as country)

select split(regexp_extract(country,'^\\\\["(.*)\\\\"]$',1),'","')

from releases;

["us","ca","fr"]

--------

with releases as (select '["us:[abc]","ca:[abc]","fr:[abc]"]' as country)

select split(regexp_extract(country,'^\\\\["(.*)\\\\"]$',1),'","') -- 提取开头的[和结尾的]之间的内容

from releases;

["us:[abc]","ca:[abc]","fr:[abc]"]

中间的[]依然存在。

-------

with releases as (select '["us:[abc]","ca:[abc]","fr:[abc]"]' as country)
select  split(regexp_extract(country,'^\\\\["(.*)\\\\"]$',1),'","')  as  c1 , -- ["us:[abc]","ca:[abc]","fr:[abc]"]
split(regexp_extract(country,'^\\\\["(.*)\\\\"]$',0),'","')  as  c2  -- ["[\\"us:[abc]","ca:[abc]","fr:[abc]\\"]"]
     from    releases;

0表示把整个正则表达式对应的结果全部返回
1表示返回正则表达式中第一个() 对应的结果 以此类推

Hive,regexp_extract用法--注意圆括号!!

end

以上是关于Hive str to array / regexp_extract的主要内容,如果未能解决你的问题,请参考以下文章

Hive:map字段存储和取用 ( str_to_map函数 )

AWS Elastic Map Reduce Hive 运行 v0.5?缺少函数:“str_to_map”、“reflect”

hive函数--02---split() lateral view explode() posexplode()

TypeError:打印时需要一个整数(得到类型 str) ar = array("B", ['hello', 'to', 'myuniVerse'])

hive UDF

hive sql split 分隔符