Hive extract data from Nested Array

Nirmal Prabhu

Hi need to extract data from an array of array, Im using Athena

create external table test
(
customer string
)
Location 'something-something'

The single row of this table is,

select * from customer limit 1

{ "ID": "XXXX", "USerDate": { "items": [{ "Name": "Nir", "CLG": "NPT", "Place": "CBE", "Any Group": {}, "Interest": { "items": [{ "Games": "Cricket", "Music": "AR" }] }, "Others": {} }] } }

I need to extract the row as like

| ID | Name | Place | Games| Music |

|-----|---------|----------|----------|-----------|

David דודו Markovitz
select  json_extract_scalar(customer,'$.ID')    as ID
       ,json_extract_scalar(i1.item,'$.Name')   as Name
       ,json_extract_scalar(i1.item,'$.Place')  as Place
       ,json_extract_scalar(i2.item,'$.Games')  as Games
       ,json_extract_scalar(i2.item,'$.Music')  as Music

from    test

        cross join unnest (cast(json_extract(customer,'$.USerDate.items') 
            as array(json))) as i1 (item)

        cross join unnest (cast(json_extract(i1.item,'$.Interest.items')
            as array(json))) as i2 (item)
;

  ID  | Name | Place |  Games  | Music
------+------+-------+---------+-------
 XXXX | Nir  | CBE   | Cricket | AR

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to extract data from this nested array

From Dev

ionic 3 - Extract data from nested JSON into an array

From Dev

Extract an array from nested one

From Dev

Extract data from nested lists

From Dev

HIVE nested ARRAY in MAP data type

From Dev

create nested data from from un-nested data in hive

From Dev

create nested data from from un-nested data in hive

From Dev

Extract DataFrame from nested, tagged array in Spark

From Dev

Extract JSON Array from data

From Dev

Extract data into array from foreach

From Dev

Extract data into array from foreach

From Dev

Extract data from an array of Object

From Dev

Node js extract data from a nested function

From Dev

Extract data from the nested parenthesis in bash

From Dev

Unable to extract the data from the Nested JSON path

From Dev

How to extract array values within nested JSON data

From Dev

How to extract data from a json array with php?

From Dev

Extract data from Array/Object in PHP?

From Dev

extract data from stdClass object array

From Dev

Extract a subset of data from numpy array

From Dev

Extract data from 2d array

From Dev

How to extract data from a json array with php?

From Dev

How to extract data from this array in ci

From Dev

extract data from array that begins with "http" only

From Dev

Extract data from a promise Object or Array

From Dev

Gatling - extract data from JSON array response

From Dev

JavaScript extract data from variable / array

From Dev

Extract data from serialized array and output into PHP

From Dev

How do I extract a specific object from a nested array?