str_to_hive函数将字符串的每个字符拆分为键

时间:2019-01-11 07:56:49

标签: string dictionary hive

我在蜂巢的字符串列之一中有一个字符串"description=Qiemo|locationToolsID=733"。当我尝试使用定界符|(对于每个KV)和=(对于键和值)将其转换为映射时,则不起作用。

具体来说,当我跑步时:

str_to_map(str('description=Qiemo|locationToolsID=733'),'|','=').

我期待中

description:Qiemo
locationToolsID:733

但是我越来越像这样

{"a":null,"":"","c":null,"d":null,"D":null,"e":null,"i":null,"I":null,"l":null,"m":null,"n":null,"o":null,"p":null,"Q":null,"r":null,"s":null,"3":null,"t":null,"T":null,"7":null,"|":null}

这是怎么回事?

1 个答案:

答案 0 :(得分:1)

您必须转义|字符,因为它在Java正则表达式中具有特殊含义。 您可以尝试以下方法:

select str_to_map("description=Qiemo|locationToolsID=733",'\\\|','=');
                         OR
select str_to_map("description=Qiemo|locationToolsID=733",'[|]','=');

输出为:{"locationToolsID":"733","description":"Qiemo"}