iphonex录音在哪里-word拼写检查

hms core
2023年4月3日发(作者:花生壳ddns)

通过JavaAPI获取HiveMetastore中的元数据信息

在⽂章中,我们说到Hive3.0.0版本开始,其单独提供了standalonemetastore服务以作为像presto等处理引擎的元数据管理中⼼。

本⽂以JavaAPI为例,介绍如何获取hivestandalonemetastore中的catalog、database、table等信息,通过该⽅式,我们可以⽅便地

对元数据中⼼进⾏监控与管理。

当然,⾸先要在maven项⽬中导⼊如下依赖(以hive3.1.2为例)

hive-standalone-metastore

3.1.2

接着便可以通过如下⽅式建⽴客户端IMetaStoreClient与HMS进⾏连接

/**

*初始化HMS连接

*@urationHMS连接信息

*@returnIMetaStoreClient

*@throwsMetaException异常

*/

publicstaticIMetaStoreClientinit(Configurationconf)throwsMetaException{

try{

xy(conf,false);

}catch(MetaExceptione){

("hms连接失败",e);

throwe;

}

}

⽽HMS的连接信息有两种⽅式可以提供,⼀种是通过配置⽂件的形式,另⼀种则是指定""参数,具体如

下所⽰:

Configurationconf=newConfiguration();

//通过""参数提供HMS连接信息

("","thrift://192.168.1.3:9083");

//通过⽅式提供HMS连接信息

//ource("");

IMetaStoreClientclient=(conf);

通过上述⽅式建⽴与HMS连接的客户端之后,便可以通过下述接⼝获取catalog等信息

n("----------------------------获取所有catalogs-------------------------------------");

alogs().forEach(::println);

n("------------------------获取catalog为hive的描述信息--------------------------------");

n(alog("hive").toString());

n("--------------------获取catalog为hive的所有database-------------------------------");

Databases("hive").forEach(::println);

n("---------------获取catalog为hive,database为hive的描述信息--------------------------");

n(abase("hive","hive_storage"));

n("-----------获取catalog为hive,database名为hive_storage下的所有表--------------------");

les("hive","hive_storage","*").forEach(::println);

n("------获取catalog为hive,database名为hive_storage,表名为sample_table_1的描述信息-----");

n(le("hive","hive_storage","sample_table_1").toString());

如果要了解更多使⽤⽅法,可参考类

下⾯为具体代码实现:

maven项⽬的⽂件

<?xmlversion="1.0"encoding="UTF-8"?>

schemaLocation="/POM/4.0.0/xsd/">

4.0.0

hms-client

1.0-SNAPSHOT

hms-client

UTF-8

<>1.7

<>1.7

junit

junit

4.11

test

hive-standalone-metastore

3.1.2

maven-clean-plugin

3.1.0

maven-site-plugin

3.7.1

maven-project-info-reports-plugin

3.0.0

s

maven-compiler-plugin

8

8

测试代码

package;

importConfiguration;

importIMetaStoreClient;

importRetryingMetaStoreClient;

importMetaException;

importLogger;

importLoggerFactory;

publicclassHMSClient{

publicstaticfinalLoggerLOGGER=ger();

/**

*初始化HMS连接

*@uration

*@returnIMetaStoreClient

*@throwsMetaException异常

*/

publicstaticIMetaStoreClientinit(Configurationconf)throwsMetaException{

try{

xy(conf,false);

}catch(MetaExceptione){

("hms连接失败",e);

throwe;

}

}

publicstaticvoidmain(String[]args)throwsException{

Configurationconf=newConfiguration();

("","thrift://192.168.1.3:9083");

//ource("");

IMetaStoreClientclient=(conf);

n("----------------------------获取所有catalogs-------------------------------------");

alogs().forEach(::println);

n("------------------------获取catalog为hive的描述信息--------------------------------");

n(alog("hive").toString());

n("--------------------获取catalog为hive的所有database-------------------------------");

Databases("hive").forEach(::println);

n("---------------获取catalog为hive,database为hive的描述信息--------------------------");

n(abase("hive","hive_storage"));

n("-----------获取catalog为hive,database名为hive_storage下的所有表--------------------");

les("hive","hive_storage","*").forEach(::println);

n("------获取catalog为hive,database名为hive_storage,表名为sample_table_1的描述信息-----");

n(le("hive","hive_storage","sample_table_1").toString());

}

}

运⾏结果

----------------------------获取所有catalogs-------------------------------------

hive

------------------------获取catalog为hive的描述信息--------------------------------

Catalog(name:hive,description:DefaultcatalogforHive,locationUri:file:/user/hive/warehouse)

--------------------获取catalog为hive的所有database-------------------------------

default

hive

hive_storage

---------------获取catalog为hive,database为hive的描述信息--------------------------

Database(name:hive_storage,description:null,locationUri:s3a://hive-storage/,parameters:{},ownerName:root,ownerType:USER,catalogName:hive)

-----------获取catalog为hive,database名为hive_storage下的所有表--------------------

sample_table_1

------获取catalog为hive,database名为hive_storage,表名为sample_table_1的描述信息-----

Table(tableName:sample_table_1,dbName:hive_storage,owner:root,createTime:1641540923,lastAccessTime:0,retention:0,sd:StorageDescriptor(cols:[

FieldSchema(name:col1,type:string,comment:null),FieldSchema(name:col2,type:string,comment:null)],location:s3a://hive-storage/sample_table_1,inpu

tFormat:utFormat,outputFormat:putFormat,compressed:false,numBuck

ets:0,serdeInfo:SerDeInfo(name:sample_table_1,serializationLib:de,parameters:{}),bucketCols:[],sortCols:[],pa

rameters:{},skewedInfo:SkewedInfo(skewedColNames:[],skewedColValues:[],skewedColValueLocationMaps:{}),storedAsSubDirectories:false),partitionK

eys:[],parameters:{presto_query_id=20220107_073521_00018_favj9,totalSize=366,numRows=1,rawDataSize=22,COLUMN_STATS_ACCURATE={"CO

LUMN_STATS":{"col1":"true","col2":"true"}},numFiles=1,transient_lastDdlTime=1641540923,=false,STATS_GENERATED_VIA_STATS_TASK

=workaroundforpotentiallackofHIVE-12730,presto_version=366},viewOriginalText:null,viewExpandedText:null,tableType:MANAGED_TABLE,rewriteE

nabled:false,catName:hive,ownerType:USER)

更多推荐

hms core