问题
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