hive启用LAST_ACCESS_TIME(访问时间)

1.hive-site.xml 的 Hive 服务高级配置代码段(安全阀)中添加2个参数:

hive.security.authorization.sqlstd.confwhitelist=hive.exec.pre.hooks

hive.exec.pre.hooks=org.apache.hadoop.hive.ql.hooks.UpdateInputAccessTimeHook$PreExec

2.重启hive即可

<property><name>hive.security.authorization.sqlstd.confwhitelistname><value>hive.exec.pre.hooksvalue>
property><property><name>hive.exec.pre.hooksname><value>org.apache.hadoop.hive.ql.hooks.UpdateInputAccessTimeHook$PreExecvalue>
property>
SELECT *
FROM TBLS
WHERE TBL_NAME = 'student3';

在这里插入图片描述

show table extended like student3;
hive (default)>>>>>> show table extended like student3;
OK
tab_name
tableName:student3
owner:atguigu
location:hdfs://hadoop102:8020/user/hive/warehouse/student3
inputformat:org.apache.hadoop.mapred.TextInputFormat
outputformat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
columns:struct columns { i32 id, string name}
partitioned:false
partitionColumns:
totalNumberFiles:1
totalFileSize:7
maxFileSize:7
minFileSize:7
lastAccessTime:1686048455210
lastUpdateTime:1685972721193Time taken: 0.216 seconds, Fetched: 15 row(s)
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
import org.apache.hadoop.hive.metastore.api.Table;
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;/***/
public class Test2 {public static void main(String[] args) throws Exception {HiveConf hiveConf = new HiveConf();MetastoreConf.setVar(hiveConf,MetastoreConf.ConfVars.THRIFT_URIS ,"thrift://hadoop102:9083" );HiveMetaStoreClient hiveClient = new HiveMetaStoreClient(hiveConf);Table aaa = hiveClient.getTable("default", "student3");int lastAccessTime = aaa.getLastAccessTime();System.out.println("lastAccessTime = " + lastAccessTime);System.out.println(aaa.getTableName());//        String schema = "blending";
//        HCatClient client = HCatalogClient.getClient(null);
//        List tables = client.listTableNamesByPattern(schema, "*");
//        for(String table : tables) {
//            HCatTable hTable = client.getTable(schema, table);
//            System.out.println("Table name is :" +hTable.getTableName());
//            System.out.println("Input file format is:"+hTable.getInputFileFormat());
//            System.out.println("Output file format is:"+hTable.getOutputFileFormat());
//        }
//
//        HCatCli hCatCli = new HCatCli();}}

结果:

lastAccessTime = 1686049690

查询分区信息:

show table extended like dim_user_zip PARTITION(dt='9999-12-31');

在这里插入图片描述
在这里插入图片描述
查询总大小:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部