AWS Athena (Presto) how to transpose map to columns

Viewed 1249

AWS Athena query question;

I have a nested map in my rows, of which I would like to transpose the keys to columns. I could name the columns explicitly like items['label_a'], but in this case the keys are actually dynamic...

From these rows:

{id=1, items={label_a=foo, label_b=foo}}
{id=2, items={label_a=bar, label_c=bar}}
{id=3, items={label_b=baz, label_c=baz}}

I would like to get a table like so:

| id | label_a | label_b | label_c |
------------------------------------
| 1  |   foo   |   foo   |         |  
| 2  |   bar   |         |   bar   |  
| 3  |         |   baz   |   baz   |  

Is that possible and how to do this in aws athena (presto version 0.172)?

Thanks!

1 Answers
Related