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

时间:2017-03-18 17:56:01

标签: json amazon-web-services hive amazon-athena

我正在尝试分析Athena中的AWS云跟踪日志,因为如果我选择安全组添加入站规则事件,它将在元素列中返回以下字符串。

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

但我从json结果中仅需要groupId。那我该怎么办呢?

  

注意:表格是外部表格

1 个答案:

答案 0 :(得分:0)

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