hive从json行中选择一个特定的字符串

bq9c1y66  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(439)

我正在尝试分析athena中的aws云跟踪日志,如果我选择security group add inbound rules event,它将在elements列中返回下面的字符串。

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

但我需要 groupId 唯一的结果。那我怎么才能得到呢?
注意:表是一个外部表

42fyovps

42fyovps1#

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

相关问题