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
demandé il y a 7 mois91 vues
Aucune réponse

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions