我正在尝试获取 Hive 中表的最后修改时间戳。
请使用以下命令:
show TBLPROPERTIES table_name ('transient_lastDdlTime');
从 Hive 表中获取transient_lastDdlTime。
SHOW CREATE TABLE table_name;
然后将transient_lastDdlTime复制粘贴到下面的查询中以获取时间戳形式的值。
SELECT CAST(from_unixtime(your_transient_lastDdlTime_value) AS timestamp);
在上述答案的帮助下,我为即将到来的开发人员创建了一个简单的解决方案。
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
我使用了 beeline 别名。确保正确设置别名并调用上述脚本。如果没有使用别名,则通过替换上面的 beeline 来使用完整的 beeline 命令(带有 jdbc 连接)。如果有问题请在评论中留言。
这里已经有一个关于如何查看 Hive 表的上次修改日期的答案。我只是分享如何检查 Hive 表分区的上次修改日期。
连接到 hive 集群以运行 hive 查询。在大多数情况下,您只需运行 hive 命令即可连接:hive
DESCRIBE FORMATTED <database>.<table_name> PARTITION(<partition_column>=<partition_value>);
在回复中你会看到类似这样的内容:
transient_lastDdlTime 1631640957
SELECT CAST(from_unixtime(1631640957) AS timestamp);
执行即可获取时间戳
describe formatted table_name
您可以执行以下命令并将
transient_lastDdlTime
的输出从时间戳转换为日期。show create table TABLE_NAME;
这个transient_lastDdlTime给出了最后一次选择运行的时间,不需要修改
如果您使用 mysql 作为元数据,请使用以下...
select TABLE_NAME, UPDATE_TIME, TABLE_SCHEMA from TABLES where TABLE_SCHEMA = 'employees';