一、设置hbase节点
set hbase.zookeeper.quorum=zookeeper节点ip;
二、创建hive的外表关联hbase,删除外表不会删除对应hbase表
CREATE EXTERNAL TABLE hive_hbase_external_table(key int, name String,age String)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:name,cf1:age")
TBLPROPERTIES ("hbase.table.name" = "hbase_table",
"hbase.mapred.output.outputtable" = "hbase_table");
三、创建一张原始的hive表,准备一些数据
create table hive_data (key String,name String,age String);
insert into hive_data values(1,"zhangsan","18");
insert into hive_data values(2,"lisi","22");
四、把hive原表hive_data的数据,通过hive表hive_hbase_table导入到hbase的表hbase_table中
insert into table hive_hbase_external_table select * from hive_data;
五、查看hbase表hbase_table中是否有数据
hbase:005:0> scan 'hbase_table'
ROW COLUMN+CELL
1 column=cf1:age, timestamp=2023-10-26T16:09:00.197, value=18
1 column=cf1:name, timestamp=2023-10-26T16:09:00.197, value=zhangsan
2 column=cf1:age, timestamp=2023-10-26T16:09:00.197, value=22
2 column=cf1:name, timestamp=2023-10-26T16:09:00.197, value=lisi
2 row(s)
Took 0.1312 seconds