-
大小: 14KB文件類型: .zip金幣: 2下載: 1 次發布日期: 2022-09-30
- 語言: Java
- 標簽: hive,hbase??bulkloa??
資源簡介
基于hadoop的,java實現hive快速導數據到Hbase解決方案。

代碼片段和文件信息
package?edu.wzm;
import?edu.wzm.transform.RCFileToHFile;
import?edu.wzm.utils.HiveTableUtils;
import?org.apache.hadoop.conf.Configuration;
import?org.apache.hadoop.conf.Configured;
import?org.apache.hadoop.fs.Path;
import?org.apache.hadoop.hbase.HbaseConfiguration;
import?org.apache.hadoop.hbase.KeyValue;
import?org.apache.hadoop.hbase.client.HbaseAdmin;
import?org.apache.hadoop.hbase.client.HTable;
import?org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import?org.apache.hadoop.hbase.mapreduce.HFileOutputFormat;
import?org.apache.hadoop.hbase.mapreduce.SimpleTotalOrderPartitioner;
import?org.apache.hadoop.hive.conf.HiveConf;
import?org.apache.hadoop.hive.metastore.HivemetaStoreClient;
import?org.apache.hadoop.hive.ql.metadata.Table;
import?org.apache.hadoop.hive.serde2.objectinspector.StructField;
import?org.apache.hadoop.mapreduce.Job;
import?org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import?org.apache.hadoop.util.GenericOptionsParser;
import?org.apache.hadoop.util.Tool;
import?org.apache.hadoop.util.ToolRunner;
import?org.apache.hive.hcatalog.common.HCatUtil;
import?org.apache.hive.hcatalog.rcfile.RCFileMapReduceInputFormat;
import?java.util.List;
/**
?*?Created?by?GatsbyNewton?on?2016/3/24.
?*/
public?class?Driver?extends?Configured?implements?Tool{
????private?static?Configuration?conf?=?new?Configuration();
????private?static?Configuration?hconf?=?null;
????private?static?HbaseAdmin?hadmin?=?null;
????public?static?void?connectHbase(){
????????final?String?Hbase_CONFIG_ZOOKEEPER_CLIENT?=?“hbase.zookeeper.property.clientPort“;
????????final?String?Hbase_ZOOKEEPER_CLIENT_PORT?=?“2181“;
????????final?String?Hbase_CONFIG_ZOOKEEPER_QUORUM?=?“hbase.zookeeper.quorum“;
????????final?String?Hbase_ZOOKEEPER_SERVER?=?“hbase38hbase43hbase00“;
????????conf.set(Hbase_CONFIG_ZOOKEEPER_CLIENT?Hbase_ZOOKEEPER_CLIENT_PORT);
????????conf.set(Hbase_CONFIG_ZOOKEEPER_QUORUM?Hbase_ZOOKEEPER_SERVER);
????????hconf?=?HbaseConfiguration.create(conf);
????????try{
????????????hadmin?=?new?HbaseAdmin(hconf);
????????}
????????catch?(Exception?e){
????????????e.printStackTrace();
????????}
????}
????public?static?void?main(String[]?args)throws?Exception{
????????String[]?otherArgs?=?new?GenericOptionsParser(conf?args).getRemainingArgs();
????????if(otherArgs.length?!=?4){
????????????System.err.println(“Usage:????setable>“);
????????????System.exit(1);
????????}
????????String?path?=?System.getProperty(“user.dir“)?+?otherArgs[2];
????????List?fieldNames?=?HiveTableUtils.getFieldName(path);
????????StringBuilder?sb?=?new?StringBuilder(fieldNames.get(0));
????????int?size?=?fieldNames.size();
????????for(int?i?=?1;?i?????????????sb.append(“:“).append(fieldNames.get(i));
????????}
????????conf.set(“schema“?sb.toString());
System.exit(ToolRunner.run(conf?new?Driver()?otherArgs));
????}
????@SuppressWarnings(“deprecation“)
????@Override
????public?int?run(String[]?strings)?throws?Ex
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-11-05?16:10??hive-bulkload-hba
?????文件?????????272??2017-11-05?16:10??hive-bulkload-hba
?????文件???????11357??2017-11-05?16:10??hive-bulkload-hba
?????文件????????3003??2017-11-05?16:10??hive-bulkload-hba
?????目錄???????????0??2017-11-05?16:10??hive-bulkload-hba
?????文件?????????561??2017-11-05?16:10??hive-bulkload-hba
?????文件????????2479??2017-11-05?16:10??hive-bulkload-hba
?????目錄???????????0??2017-11-05?16:10??hive-bulkload-hba
?????文件?????????635??2017-11-05?16:10??hive-bulkload-hba
?????目錄???????????0??2017-11-05?16:10??hive-bulkload-hba
?????目錄???????????0??2017-11-05?16:10??hive-bulkload-hba
?????目錄???????????0??2017-11-05?16:10??hive-bulkload-hba
?????目錄???????????0??2017-11-05?16:10??hive-bulkload-hba
?????目錄???????????0??2017-11-05?16:10??hive-bulkload-hba
?????文件????????3941??2017-11-05?16:10??hive-bulkload-hba
?????文件????????4173??2017-11-05?16:10??hive-bulkload-hba
?????目錄???????????0??2017-11-05?16:10??hive-bulkload-hba
?????文件????????2619??2017-11-05?16:10??hive-bulkload-hba
?????目錄???????????0??2017-11-05?16:10??hive-bulkload-hba
?????文件????????1468??2017-11-05?16:10??hive-bulkload-hba
評論
共有 條評論