有没有办法在 AWS Athena 中展平结构字段?

Is there a way to flatten a struct field in AWS Athena?

我正在尝试编写一个 Athena 查询,它将允许我在 select 语句中扩展一个结构。

假设我有一个 table my_table 看起来像:

id string,
metadata struct<field1:varchar,field2:int>

我知道通过在查询中放置名称 field1 我可以从结构中提取字段,但我想要更通用的东西,例如 metadata.* 这样模式就可以是抽象的。

这可以通过 Python 和一些库轻松完成,但想检查 Athena 中是否没有任何可以完成的事情。

谢谢!

I would like it if something like select results.id, results.scores.* from my_table results worked, but unfortunately it doesn't.

您要的是“通用所有字段参考”。 它自 Presto 323 起在 Presto 中可用。 您可以从 https://trino.io/download.html.

下载最新的 Presto 版本

遗憾的是,Athena 当前基于 Presto .172(3 年前发布),因此此功能在那里不可用。在升级 Athena 之前,您无法在 SQL 级别上应用解决方法。您需要在从 Athena 读取数据的应用程序中对此进行补偿。或者,您可以 deploy recent Presto version on AWS easily.