Athena: how to get information from json_array

0

If I want to extract specific properties from a JSON array using SQL, for example, if the requestparameters structure is as follows:

{
  'gree': [
    {
      'Grantee': {
        'xsi:type': 'CanonicalUser',
        'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
        'ID': 'xx'
      },
      'Permission': 'READ'
    },
    {
      'Grantee': {
        'xsi:type': 'CanonicalUser',
        'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
        'ID': 'xx'
      },
      'Permission': 'WRITE'
    },
    {
      'Grantee': {
        'xsi:type': 'CanonicalUser',
        'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
        'ID': 'xx'
      },
      'Permission': 'WRITE_ACP'
    }
  ]
}

If i were using MySQL, you could use the following syntax to extract all the ID properties and Permission properties:

SELECT
  json_extract(requestparameters, '$.gree[*].Grantee.ID') as ID,
  json_extract(requestparameters, '$.gree[*].Permission') as Permission
FROM table;

However, using [ * ] in this way is not valid syntax for Athena and would result in an error like 'INVALID_FUNCTION_ARGUMENT: Invalid JSON path: '$.AccessControlPolicy.AccessControlList.Grant[ * ].Permission''. If you replace [ * ] with [0], you can extract information from the first element. The question is, how can you extract properties from all elements?"

chunhui
質問済み 7ヶ月前91ビュー
回答なし

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ