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.confwhitelist</name>
<value>hive.exec.pre.hooks</value>
</property>
<property>
<name>hive.exec.pre.hooks</name>
<value>org.apache.hadoop.hive.ql.hooks.UpdateInputAccessTimeHook$PreExec</value>
</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:1685972721193
Time 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<String> 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');
查询总大小: