Get Table Properties out of Hive using Java API

断了今生、忘了曾经 提交于 2019-11-27 08:33:25

问题


I'm trying to get table properties like table db, name, owner, and hdfs location out of the hive metastore using the metastore client in java. I think I can get the table databases and names okay, but I can't figure out how to grab things like owner and hdfs location. Is it possible? I've been searching the doc and internet for a couple hours now and no dice.


回答1:


Could be something like that:

org.apache.hadoop.hive.metastore.api.Table table=..........;
org.apache.hadoop.hive.metastore.api.StorageDescriptor sd=table.getSd();
String loc=sd.getLocation();
String own=sd.getOwner();

https://hive.apache.org/javadocs/r1.2.2/api/org/apache/hadoop/hive/metastore/api/Table.html https://hive.apache.org/javadocs/r1.2.2/api/org/apache/hadoop/hive/metastore/api/StorageDescriptor.html




回答2:


If it is a partitioned table, you can do a :

describe formatted table partition(partition_name=partition_value).

It will display the underlying hdfs path and the owner of the table.




回答3:


I ran the following command on my virtualbox having Cloudera CDH 5.1.0

$ hive -e "describe extended tablename"

The output of this command provides information in addition to tablename, dbname, owner, createtime, location. You can also refer the following CWIKI link for more details

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Describe



来源:https://stackoverflow.com/questions/33880050/get-table-properties-out-of-hive-using-java-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!