presto:从字符串列中提取值,类似于map,但不是map

zfciruhq  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(441)

我有一张table:

Name  pets
--------------
Andy  {"cat":2, "dog":1, "bird":4 ,xxx}
John  {"dog":3, "cat":1, "bird":{}, uyx}
Mary  {"dog":2, "duck":{}, "cat":1, zzz}

pets列是一个Map,但是table creator是一个字符串,其中包含一些额外的字符。所以我不能用 cast(json_parse(pets) as map(varchar, varchar)) AS m .
在这种情况下,如果我想找出 "cat" ,我该怎么做?谢谢您!

j8ag8udp

j8ag8udp1#

你可以用 regexp_extract() :

select t.*,
       regexp_extract(pets, '"cats":([^,]*)', 1)
from t;

相关问题