如何获取 hive 表、列、视图、约束键和注释列的元数据?

rav*_*dar 2 hadoop hive

请帮助我了解如何获取 hive 表、列、视图、约束键和注释列的元数据。

小智 5

如果您有 Hue 可用,您可以从顶部菜单数据浏览器转到 Metastore 表。您可以在那里找到所有可用模式的元数据。从 Hive 您可以尝试:
USE DB_NAME;
DESCRIBE FORMATTED TABLE_NAME;

DESCRIBE EXTENDED TABLE_NAME;


dev*_*v ツ 0

使用 Hcatlog。

Maven 依赖:

    <dependency>
        <groupId>org.apache.hive.hcatalog</groupId>
        <artifactId>hive-webhcat-java-client</artifactId>
        <version>1.2.1</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

示例代码:

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);
}
Run Code Online (Sandbox Code Playgroud)

检查HCatTable的可用方法。