如何在HIVE表中找到最新的分区 [英] How to find the most recent partition in HIVE table
问题描述
我有一个分区表 - 有201个分区。
我需要在此表中找到最新的分区,并使用它来后处理我的数据。查找所有分区的列表是:
use db;
显示分区表名;
我需要查询来查找最新的这些分区。分区格式为
ingest_date = 2016-03-09
我尝试使用max(),这给了我一个错误的结果。我不希望遍历整个表
从db.table_name中选择max(ingest_date);
这会给我预期的输出结果..但是在第一个地方杀掉了所有分区。
是否有更高效的查询来获取HIve表的最新分区?
您可以使用显示分区:
hive -eset hive.cli.print.header = false; show partitions table_name; |尾-1 | cut -d'='-f2
这会给你2016-03-09作为输出。
I have a partitioned table - with 201 partitions. I need to find latest partition in this table and use it to post process my data. The query to find list of all partitions is :
use db;
show partitions table_name;
I need a query to find the latest of these partitions. The partitions are in format
ingest_date=2016-03-09
I tried using max() which gave me a wrong result. I do not want to traverse through entire table by doing
select max(ingest_date) from db.table_name;
This would give me the expected output.. but kill the whole point of having partitions in the 1st place.
Is there a more efficient query to get the latest partition for HIve table ?
You can use "show partitions":
hive -e "set hive.cli.print.header=false;show partitions table_name;" | tail -1 | cut -d'=' -f2
This will give you "2016-03-09" as output.
这篇关于如何在HIVE表中找到最新的分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!