简体   繁体   中英

How to getting latest partition data from hive

I need to fetch all records from a table in hive which is having latest partitions. The table is partitioned by date,year,month eg (date=25,year=2020,month=3) , likewise there will be many partitions.

The partitions are not static and it will be changing frequently. I am trying to handle of getting the latest partition in the query. Can anybody help me to write the query?

在此处输入图片说明

Try this:

select * 
  from your_table t
 where concat_ws('-',t.year,t.month,t.date) in (select max(concat_ws('-',s.year,s.month,s.date)) from your_table s)

Also read these related answers:

https://stackoverflow.com/a/59675908/2700344

https://stackoverflow.com/a/41952357/2700344

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM