How to get lastaltertimestamp from Hive table?

烈酒焚心 提交于 2021-01-27 13:56:04

问题


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

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