Hive select a particular string from a json row

元气小坏坏 提交于 2019-12-14 02:29:23

问题


Im trying to analyze AWS cloud trail logs in Athena, for that If I select security group add inbound rules event it returns the below string in elements column.

{"groupId":"sg-XXXX","ipPermissions":{"items":[{"ipProtocol":"tcp","fromPort":22,"toPort":22,"groups":{},"ipRanges":{"items":[{"cidrIp":"0.0.0.0/0"}]},"prefixListIds":{}}]}}

But I need groupId alone from that json results. So how can I get that ?

Note: The tables is an external table


回答1:


select json_extract_scalar('{"groupId":"sg-XXXX","ipPermissions":{"items":[{"ipProtocol":"tcp","fromPort":22,"toPort":22,"groups":{},"ipRanges":{"items":[{"cidrIp":"0.0.0.0/0"}]},"prefixListIds":{}}]}}','$.groupId');
OK
sg-XXXX


来源:https://stackoverflow.com/questions/42877874/hive-select-a-particular-string-from-a-json-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!