AWS Athena (Presto) how to transpose map to columns

青春壹個敷衍的年華 提交于 2021-02-05 10:51:23

问题


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:


This is not possible in a dynamic manner due to the fact that output columns need to be know to the planner before the query execution starts.

See the previous discussion here: https://github.com/prestosql/presto/issues/2448 and https://github.com/prestosql/presto/issues/1206.



来源:https://stackoverflow.com/questions/62717002/aws-athena-presto-how-to-transpose-map-to-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!