1. 程式人生 > >hive 建立(內外部)表 時 同時建立Hbase表

hive 建立(內外部)表 時 同時建立Hbase表

hive 建立內部表 時 同時自動建立Hbase表,刪除Hive內部表時,也會自動刪除hbase表
CREATE TABLE student_hive_hbase(
id int,
name string,
age int,
height int)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:name,cf1:age,cf1:height") 
TBLPROPERTIES ("hbase.table.name" = "student_hive_hbase");

注意:key 預設是第一個欄位(id)

此時hive表與hbase表都建立了

從已有Hive表student導資料到student_hive_hbase表
insert into student_hive_hbase select*from student;

檢視student_hive_hbase表是否有資料
select * from student_hive_hbase;

檢視hbase student_hive_hbase 是否有資料
hbase(main):003:0> scan 'student_hive_hbase'
ROW                                                                  COLUMN+CELL                                                                                                                                                                                              
 1                                                                   column=cf1:age, timestamp=1540522220850, value=21                                                                                                                                                        
 1                                                                   column=cf1:height, timestamp=1540522220850, value=80                                                                                                                                                     
 1                                                                   column=cf1:name, timestamp=1540522220850, value=zhangsan    


Hive 建外部表 (需要在hbase手動執行建表語句),好處是 刪除hive中的student_hive_hbase表時
不會自動刪除hbase 中的student_hive_hbase表。

create 'student_hive_hbase', 'cf1'

CREATE EXTERNAL TABLE student_hive_hbase(
id int,
name string,
age int,
height int)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:name,cf1:age,cf1:height") 
TBLPROPERTIES ("hbase.table.name" = "student_hive_hbase");