简体   繁体   English

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

[英]str_to_hive function splits each character of the string as key

I have a string "description=Qiemo|locationToolsID=733" in one of the string column in hive.我在 hive 的字符串列之一中有一个字符串"description=Qiemo|locationToolsID=733" When I try to convert this to map using the delimiter |当我尝试使用分隔符将其转换为地图时| for each KV and = for key and value, it doesn't work.对于每个 KV 和=键和值,它不起作用。

Specifically, when I run:具体来说,当我运行时:

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

I was expecting我期待

description:Qiemo
locationToolsID:733

but I am getting like this但我越来越像这样

{"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}

What is going on here?这里发生了什么?

You have to escape the |你必须逃离| character as it has special meaning in Java regular expression.字符,因为它在 Java 正则表达式中具有特殊含义。 You can try this:你可以试试这个:

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

Output would be: {"locationToolsID":"733","description":"Qiemo"}输出将是: {"locationToolsID":"733","description":"Qiemo"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM