Please help me out how get metadata of hive tables, columns, views, constraint keys and comment columns.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It can be viewed by this simple query describe formatted table_name
回答2:
Use Hcatlog.
Maven dependency:
<dependency>
<groupId>org.apache.hive.hcatalog</groupId>
<artifactId>hive-webhcat-java-client</artifactId>
<version>1.2.1</version>
</dependency>
Sample code:
HiveConf hcatConf = new HiveConf();
hcatConf.setVar(HiveConf.ConfVars.METASTOREURIS, connectionUri);
hcatConf.set("hive.metastore.local", "false");
HCatClient client = null;
HCatTable hTable = null;
try {
client = HCatClient.create(hcatConf);
hTable = client.getTable(databaseName, tableName);
System.out.println(hTable.getLocation());
System.out.println(hTable.getInputFileFormat());
System.out.println(hTable.getOutputFileFormat());
// other properties
} catch (HCatException hCatEx) {
LOG.error("Not able to connect to hive. Caused By;", hCatEx);
}
Check available methods of HCatTable.
回答3:
if you have Hue available you can go to Metastore Tables from the top menu Data Browsers. There you can find metadata for all schemas available for you.
From Hive you can try:
USE DB_NAME;
DESCRIBE FORMATTED TABLE_NAME;
or
DESCRIBE EXTENDED TABLE_NAME;
回答4:
If you access to hive metastore(rdbm systems like mysql, postgresql etc), you will be able to access complete information. Contact your cluster admin who has configured the hive metastore if you do not have the access.