hive client java_使用hive客户端java api读写hive集群上的信息

packagecom.xiaoju.dqa.prometheus.client.hive;importorg.apache.hadoop.hive.conf.HiveConf;importorg.apache.hadoop.hive.metastore.IMetaStoreClient;importorg.apache.hadoop.hive.metastore.RetryingMetaStoreClient;importorg.apache.hadoop.hive.metastore.api.Database;importorg.apache.hadoop.hive.metastore.api.FieldSchema;importorg.apache.hadoop.hive.metastore.api.MetaException;importorg.apache.thrift.TException;importorg.slf4j.Logger;importjava.util.List;public classHiveClient {protected final Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());

IMetaStoreClient client;publicHiveClient() {try{

HiveConf hiveConf= newHiveConf();

hiveConf.addResource("hive-site.xml");

client=RetryingMetaStoreClient.getProxy(hiveConf);

}catch(MetaException ex) {

logger.error(ex.getMessage());

}

}public ListgetAllDatabases() {

List databases = null;try{

databases=client.getAllDatabases();

}catch(TException ex) {

logger.error(ex.getMessage());

}returndatabases;

}publicDatabase getDatabase(String db) {

Database database= null;try{

database=client.getDatabase(db);

}catch(TException ex) {

logger.error(ex.getMessage());

}returndatabase;

}public ListgetSchema(String db, String table) {

List schema = null;try{

schema=client.getSchema(db, table);

}catch(TException ex) {

logger.error(ex.getMessage());

}returnschema;

}public ListgetAllTables(String db) {

List tables = null;try{

tables=client.getAllTables(db);

}catch(TException ex) {

logger.error(ex.getMessage());

}returntables;

}publicString getLocation(String db, String table) {

String location= null;try{

location=client.getTable(db, table).getSd().getLocation();

}catch(TException ex) {

logger.error(ex.getMessage());

}returnlocation;

}

}

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
<p> <b><span style="background-color:#FFE500;">【超实用课程内容】</span></b> </p> <p> <br /> </p> <p> <br /> </p> <p> 本课程内容包含讲解<span>解读Nginx的基础知识,</span><span>解读Nginx的核心知识、带领学员进行</span>高并发环境下的Nginx性能优化实战,让学生能够快速将所学融合到企业应用中。 </p> <p> <br /> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b><br /> </b> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b><span style="background-color:#FFE500;">【课程如何观看?】</span></b> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> PC端:<a href="https://edu.csdn.net/course/detail/26277"><span id="__kindeditor_bookmark_start_21__"></span></a><a href="https://edu.csdn.net/course/detail/27216">https://edu.csdn.net/course/detail/27216</a> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 移动端:CSDN 学院APP(注意不是CSDN APP哦) </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 本课程为录播课,课程永久有效观看时长,大家可以抓紧时间学习后一起讨论哦~ </p> <p style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <br /> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <strong><span style="background-color:#FFE500;">【学员专享增值服务】</span></strong> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b>源码开放</b> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 课件、课程案例代码完全开放给你,你可以根据所学知识,自行修改、优化 </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 下载方式:电脑登录<a href="https://edu.csdn.net/course/detail/26277"></a><a href="https://edu.csdn.net/course/detail/27216">https://edu.csdn.net/course/detail/27216</a>,播放页面右侧点击课件进行资料打包下载 </p> <p> <br /> </p> <p> <br /> </p> <p> <br /> </p>
©️2020 CSDN 皮肤主题: 1024 设计师:白松林 返回首页