Skip to content
Advertisement

Is there a way to unnest or return all the elements in an ARRAY(ROW()) in Athena?

I’ve got a column with data in the format:

array(row(action varchar,actor varchar,special_notes varchar,timestamp bigint))

where the array is guaranteed to have 1 or more elements. The arrays are not guaranteed to be the same length.

Let’s call it “my_array_row_column”. Here’s what one row of this column looks like, as an example:

I’ve tried using CROSS JOIN UNNEST(my_array_row_column) but it ends up only returning the first row() in the array. Here’s the most recent query I tried:

which, much to my dismay, only returns

when I want it to return all three rows (Morgan.Freeman, employee, newhire) as separate rows in the result, like this:

Any ideas of how I might accomplish this?

Advertisement

Answer

According to the documentation here, this is the correct pattern:

which returns

To UNNEST this would be:

Which should return

In your case

Or something like that. I think your cross join is unnecessary because you are not introducing any of the fields on the same grain as the key of the athena.movies table so there is nothing to multiply with.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement