【问题标题】:AWS Athena (Presto) how to transpose map to columnsAWS Athena(Presto)如何将映射转置到列
【发布时间】:2023-10-09 01:14:01
【问题描述】:

AWS Athena 查询问题;

我的行中有一个嵌套映射,我想将其中的键转置为列。 我可以像items['label_a'] 这样明确地命名列,但在这种情况下,键实际上是动态的......

从这些行:

{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}}

我想要一张这样的桌子:

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

这可能吗?如何在 aws athena(presto 版本 0.172)中做到这一点?

谢谢!

【问题讨论】:

    标签: presto amazon-athena


    【解决方案1】:

    这在动态方式中是不可能的,因为在查询执行开始之前需要规划器知道输出列。

    在此处查看之前的讨论:https://github.com/prestosql/presto/issues/2448https://github.com/prestosql/presto/issues/1206

    【讨论】:

    • 好吧,真可惜。我想我毕竟必须处理数据。感谢您提供此信息!