雅典娜分区位置

w6mmgewl  于 2021-06-26  发布在  Hive
关注(0)|答案(3)|浏览(362)

我可以使用

show partitions my_table

我可以通过使用

describe formatted my_table partition (partition_col='value')

但是我有很多分区,不想解析 describe formatted 如果可以避免的话。
有没有办法在一个查询中获得所有分区及其位置?

sycxhyv7

sycxhyv71#

使用 boto3 (从版本1.12.9开始)下面返回完整列表:

glue_client = boto3.client("glue")
glue_paginator = glue_client.get_paginator("get_partitions")
pages_iter = glue_paginator.paginate(
    DatabaseName=db_name, TableName=table_name
)
res = []
for page in pages_iter:
    for partition in page["Partitions"]:
        res.append(
            {
                "Values": partition["Values"],
                "Location": partition["StorageDescriptor"]["Location"],
            }
        )
sq1bmfud

sq1bmfud2#

没有内置的或一致的方式来获取这些信息。
假设您知道分区列,您可以通过如下查询获得此信息

select distinct partition_col, "$path" from my_table
qzlgjiam

qzlgjiam3#

获取表分区位置的最便宜方法是使用 GetPartitions 来自glue api的调用。它将列出所有分区、它们的值和位置。您可以使用以下aws cli工具进行尝试:

aws glue get-partitions --region us-somewhere-1 --database-name your_database --table-name the_table

使用sql-like SELECT DISTINCT partition_col, "$path" FROM the_table 可能会很昂贵,因为athena不幸地扫描了整个表以生成输出(它可能只是查看了表元数据,但这种优化似乎还不存在)。

相关问题