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;
}
}