问题
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