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회 조회
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠