I have a nested json data structure like below, end goal was to show the data in Quicksight from Athena. After researching I found out Quicksight cannot show/handle "ARRAY" datatype for visuals.
CREATE EXTERNAL TABLE `testfindings`( `
`source` string COMMENT 'from deserializer',
`account` string COMMENT 'from deserializer',
`detail` struct<findings:array<struct<productarn:string,
resources:array<struct<partition:string,type:string,region:string,id:string>>>>> COMMENT 'from deserializer')
ROW FORMAT SERDE
'org.openx.data.jsonserde.JsonSerDe'
After writing the UNNEST query in Athena to extract id, type from resources array when i try to create dataset in quicksight , i am not able to find the "ARRAY"data only "source", "account" data is shown in quicksight.
After doing some research, I found out that "ARRAY" data is not supported in quicksight so i changed my table schema as below:
CREATE EXTERNAL TABLE `testfindings`( `
`source` string COMMENT 'from deserializer',
`account` string COMMENT 'from deserializer',
`detail` string COMMENT 'from deserializer')
ROW FORMAT SERDE
'org.openx.data.jsonserde.JsonSerDe'
Now when I do select * from testfindings , i get data in three columns and last column detail has all the data in the array form.
Now, how I can get particular fields from detail column like i wanted to get id, type from resources which are present inside resources array.
`detail` struct<findings:array<struct<productarn:string,
resources:array<struct<partition:string,type:string,region:string,id:string>>>
I am trying something like this :
select
source,
account,
resource
from "testfindings"
cross join UNNEST(testfindings.detail) as p(tr)
cross join UNNEST(tr.findings) as p(it)
cross join UNNEST(it.resources) as p(resource)
It gives me below error:
INVALID_FUNCTION_ARGUMENT: Cannot unnest type: varchar
Any help is appreciated.