1.hbase數(shù)據(jù)關聯(lián)hive外部表
create external table hive_hbase_test1(id string,address string,age int,gender string,name string)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
with serdeproperties("hbase.columns.mapping"=":key,info:address,info:age,info:gender,info:name")
tblproperties("hbase.table.name"="hbase_table");
2.hive beeline導出到本地文件
beeline -u jdbc:hive2://192.168.21.110:2166 -d org.apache.hive.jdbc.HiveDriver --showHeader=false --outputformat=txt -e "select * from hive_hbase_test1" > f2.txt
showHeader=false 不要頭部碗旅,純凈模式
outputformat=txt 文件格式
f2.txt文件用? |? 隔開
3.本地文件上傳hdfs
hadoop fs -put /home/user/f2.txt /tmp/
4.hdfs導入hive
先創(chuàng)建表(注意指定表的數(shù)據(jù)格式)STORED AS TEXTFILE
create table test_2000(id string,collect_time string,create_time string,status string,value string)
row format delimited fields terminated by '|'
STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT? 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
load命令導入hive
beeline -u jdbc:hive2://192.168.1.110:2066 -e "load data inpath '/home/f2.txt' into table test_2000;"
hive表數(shù)據(jù)格式參考:https://blog.csdn.net/TC_HaoShuai/article/details/84303140
5.hive創(chuàng)建中間表關聯(lián)habse
CREATE TABLE hive_hbase_test_2000(id string,collect_time string,create_time string,status string,value string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:address,info:age,info:gender,info:name")
TBLPROPERTIES ("hbase.table.name" = "test_2000",
"hbase.mapred.output.outputtable" = "test_2000");
6.hive原數(shù)據(jù)往hive中間表導入
insert into table hive_hbase_test_2000 select * from test_2000;
查看hbase表也有了數(shù)據(jù) scan 'test_2000' 蒸健,但是這種情況刪除外部表hbase表也會沒有
7.避免hbase表與hive強關聯(lián)
可以先創(chuàng)建hbase表
create 'test_2000','info'?
然后hive外部關聯(lián)hbase表,
CREATE external TABLE hive_hbase_test_2000(id string,collect_time string,create_time string,status string,value string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:address,info:age,info:gender,info:name")
TBLPROPERTIES ("hbase.table.name" = "test_2000",
"hbase.mapred.output.outputtable" = "test_2000");