How can I find last modified timestamp for a table in Hive?

烈酒焚心 提交于 2021-02-18 10:45:06

问题


I'm trying to fetch last modified timestamp of a table in Hive.


回答1:


Please use the below command:

show TBLPROPERTIES table_name ('transient_lastDdlTime');



回答2:


Get the transient_lastDdlTime from your Hive table.

SHOW CREATE TABLE table_name;

Then copy paste the transient_lastDdlTime in below query to get the value as timestamp.

SELECT CAST(from_unixtime(your_transient_lastDdlTime_value) AS timestamp);



回答3:


You may get the timestamp by executing

describe formatted table_name



回答4:


you can execute the below command and convert the output of transient_lastDdlTime from timestamp to date.
It will give the last modified timestamp for the table.

show create table TABLE_NAME;



回答5:


With the help of above answers I have created a simple solution for the forthcoming developers.

time_column=`beeline --hivevar db=hiveDatabase --hivevar tab=hiveTable --silent=true --showHeader=false --outputformat=tsv2 -e 'show create table ${db}.${tab}' | egrep 'transient_lastDdlTime'`
time_value=`echo $time_column | sed 's/[|,)]//g' | awk -F '=' '{print $2}' | sed "s/'//g"`
tran_date=`date -d @$time_value +'%Y-%m-%d %H:%M:%S'`
echo $tran_date

I used beeline alias. Make sure you setup alias properly and invoke the above script. If there are no alias used then use the complete beeline command(with jdbc connection) by replacing beeline above. Leave a question in the comment if any.




回答6:


if you are using mysql as metadata use following...

select TABLE_NAME, UPDATE_TIME, TABLE_SCHEMA from TABLES where TABLE_SCHEMA = 'employees';


来源:https://stackoverflow.com/questions/41468759/how-can-i-find-last-modified-timestamp-for-a-table-in-hive

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