问题
Teradata has the concept of lastaltertimestamp
, which is the last time an alter table
command was executed on a table. lastaltertimestamp
can be queried. Does Hive have a similar value that can be queried?
The timestamp returned by hdfs dfs -ls /my/hive/file
does not reflect alter table
commands, so alter table
must not modify the file backing Hive file. describe formatted
does not provide a last-alter-timestamp either.
Thanks
回答1:
Hive stores metadata into a database, so files never get modified.
AFAIK the only timestamp which is tracked in HIVE is transient_lastDdlTime
.
When table is created it is the time stamp when the table was created. When any DDL is done it is the last DDL time it tooks
You can still add your custom properties to the table in order to track anything you want.
回答2:
"transient_lastDdlTime" is the property which tells about the last altered time of Hive tables. In order to fetch this along with other metadata of the Hive table you can run following query :
describe formatted <table_name>;
This outputs :
Database: xxxxxxxxx
Owner: xxxxxxxxx
CreateTime: Tue Jan xx 06:58:21 IST xxxx
LastAccessTime: UNKNOWN
Retention: 0
Location: xxxxxxxxx
Table Type: xxxxxxxxx
Table Parameters:
numFiles xxxxxxxxx
numRows xxxxxxxxx
rawDataSize xxxxxxxxx
totalSize xxxxxxxxx
transient_lastDdlTime 1517424154
# Storage Information
SerDe Library: xxxxxxxxx
InputFormat: xxxxxxxxx
OutputFormat: xxxxxxxxx
Compressed: xxxxxxxxx
Num Buckets: xxxxxxxxx
Bucket Columns: xxxxxxxxx
Sort Columns: xxxxxxxxx
Storage Desc Params:
serialization.format xxxxxxxxx
The outputted transient_lastDdlTime is in epoch format.
来源:https://stackoverflow.com/questions/40045273/how-to-get-lastaltertimestamp-from-hive-table