[英]Hive split pattern using regex
I have a problem with split pattern in hive query.我在 hive 查询中遇到了拆分模式的问题。
sample string from the table:表中的示例字符串:
['EN', 'FR', 'DE', 'IT', 'JA', 'RU', 'ZH', 'ES', 'ZH']
and now with the split function I would like to return this string in this way:现在使用拆分 function 我想以这种方式返回这个字符串:
EN
FR
...
ZH
at first I tried this way: split(data.language, ',')[1]
起初我尝试过这种方式:
split(data.language, ',')[1]
I don't know how I can get rid of square brackets and quotation marks.我不知道如何摆脱方括号和引号。
Use regexp_replace
to replace [|]|'
使用
regexp_replace
替换[|]|'
characters then split
the string column then explode
the array.字符然后
split
字符串列然后explode
数组。
select explode(split(regexp_replace(sample,"[\\[|\\'|\\]]",""),","))
from (
select string("['EN', 'FR', 'DE', 'IT', 'JA', 'RU', 'ZH', 'ES', 'ZH']")as sample
)e;
--output
--+---+
--|col|
--+---+
--| EN|
--| FR|
--| DE|
--| IT|
--| JA|
--| RU|
--| ZH|
--| ES|
--| ZH|
--+---+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.