SHOW PARTITIONS with order by in Amazon Athena

五迷三道 提交于 2019-12-04 07:21:32

I just faced the same issue and found a solution in information_schema database. If your table contains only one partitioning column, use the following query to get an ordered list:

SELECT partition_value
FROM information_schema.__internal_partitions__
WHERE table_schema = '<DB_NAME>'
        AND table_name = '<TABLE_NAME>'
ORDER BY partition_value

From your comment it sounds like you're looking to sort the partitions as a way to figure out whether or not a specific partition exists. For this purpose I suggest you use the Glue API instead of querying Athena. Run aws glue get-partition help or check your preferred SDK's documentation for how it works.

There is also a variant to list all partitions of a table, run aws glue get-partitions help to read more about that. I don't think it returns the partitions in alphabetical order, but it has operators for filtering.

The SHOW PARTITIONS command will not allow you to order the result, since this command does not produce a resultset to sort. This command only produces a string output.

You can on the other hand query the partition column and then order the result by value.

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