This article describes how the HDFs cluster information is read, and this paper says that hive
1. Resolve Dependencies First
<Properties> <hive.version>1.2.1</hive.version> </Properties><Dependency> <groupId>Org.apache.hive</groupId> <Artifactid>Hive-exec</Artifactid> <version>${hive.version}</version> <Scope>Provided</Scope> </Dependency>
2. Configuration files
Here we give a simple configuration method, which is to directly load the hive-site.xml by adding files to the configuration
For example, the configuration in Hive-site.xml is as follows
<Configuration> < Property> <name>Hive.metastore.uris</name> <value>thrift://10.91.64.23:9083,thrift://10.91.64.23:9083,thrift://10.91.64.23:9083</value> </ Property></Configuration>
3. Hive Client API
Description
1, Hiveconf.addresource ("Hive-site.xml") can directly load the configuration file into the configuration
2, Hive API is very rich, the following is only part of the introduction, if the use of other packaging can be
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 FinalLogger 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 ()); } } PublicList<string>getalldatabases () {List<String> 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; } PublicList<fieldschema>GetSchema (string db, String table) {List<FieldSchema> schema =NULL; Try{Schema=Client.getschema (db, table); } Catch(Texception ex) {Logger.error (Ex.getmessage ()); } returnschema; } PublicList<string>getalltables (String db) {List<String> 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 ; }}
Read and write information on a hive cluster using the Hive client Java API