How to get metadata of hive tables, columns, views

2019-07-25 16:00发布

Please help me out how get metadata of hive tables, columns, views, constraint keys and comment columns.

标签: hadoop hive
4条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-25 16:30

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楼-- · 2019-07-25 16:34

It can be viewed by this simple query describe formatted table_name

查看更多
太酷不给撩
4楼-- · 2019-07-25 16:41

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.

查看更多
Root(大扎)
5楼-- · 2019-07-25 16:47

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;

查看更多
登录 后发表回答