Reputation: 410
I want to get the metadata ( including storage format and storage location) of a table in Hive using JDBC. I tried searching but could not find anything related to that.
Upvotes: 0
Views: 839
Reputation: 13753
I found a better way is to use hcatalog in this case.
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());
} catch (HCatException hCatEx) {
LOG.error("Not able to connect to hive. Caused By;", hCatEx);
}
Check other methods of HCatTable.
Upvotes: 1
Reputation: 1491
Looking at this code example
You can send a describe formatted <tableName>
statement to the server, as you would send any other SELECT
statement.
Upvotes: 1