雅典娜分区位置

Kir*_*rst 4 hive presto amazon-athena

我可以使用

show partitions my_table
Run Code Online (Sandbox Code Playgroud)

我可以通过使用查看分区的位置

describe formatted my_table partition (partition_col='value')
Run Code Online (Sandbox Code Playgroud)

但是我有很多分区,describe formatted如果可以避免的话,我不想解析输出。

有没有办法在单个查询中获取所有分区及其位置?

Kir*_*rst 6

没有内置或一致的方式来获取此信息。

假设您知道分区列,您可以通过如下查询获取此信息

select distinct partition_col, "$path" from my_table
Run Code Online (Sandbox Code Playgroud)


The*_*heo 5

获取表分区位置的最便宜的方法是使用GetPartitions来自 Glue API的调用。它将列出所有分区、它们的值和位置。您可以使用 AWS CLI 工具进行尝试,如下所示:

aws glue get-partitions --region us-somewhere-1 --database-name your_database --table-name the_table
Run Code Online (Sandbox Code Playgroud)

使用 SQL likeSELECT DISTINCT partition_col, "$path" FROM the_table可能会很昂贵,因为 Athena 不幸地扫描整个表以生成输出(它可能只查看表元数据,但该优化似乎尚不存在)。