第一步,創(chuàng)建hive表,并在DLL語句中定義HBase表的表名
1浑此,創(chuàng)建表
CREATE TABLE hbase_test(
id int,
name string,
age int
)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,user:name,user:age")
TBLPROPERTIES("hbase.table.name" = "hbase_test");
注意,創(chuàng)建的這個表是管理表滞详,意味著如果刪除這個表凛俱,那么該表的所有數(shù)據(jù)(包括元數(shù)據(jù)和表數(shù)據(jù))都會被刪除。
2料饥,在DBeaver hive中查看hbase_test表
可以看到目前表還是空的蒲犬。
3,在hbase shell中岸啡,查看hbase_test表
hbase(main):036:0> scan "hbase_test"
ROW COLUMN+CELL
0 row(s)
Took 0.1718 seconds
hbase(main):037:0>
也是空的
4原叮,在hbase shell中,插入數(shù)據(jù)
hbase(main):037:0> put 'hbase_test','111','user:name','jack'
Took 0.0145 seconds
hbase(main):038:0> put 'hbase_test','111','user:age','18'
Took 0.0481 seconds
hbase(main):039:0>
5,在hbase shell中奋隶,查看hbase_test表
hbase(main):039:0> scan "hbase_test"
ROW COLUMN+CELL
111 column=user:age, timestamp=2022-01-13T10:54:05.311, value=18
111 column=user:name, timestamp=2022-01-13T10:53:55.844, value=jack
1 row(s)
Took 0.0247 seconds
hbase(main):040:0>
可以看到沛慢,表里有一行記錄
6,在hive表中插入數(shù)據(jù)
INSERT INTO hbase_test(id,name,age) VALUES(333,'mary',25);
7达布,DBeaver hive中查看hbase_test表數(shù)據(jù)
可以看到团甲,數(shù)據(jù)被成功插入
8,在hbase shell中黍聂,查看hbase_test表
hbase(main):040:0> scan "hbase_test"
ROW COLUMN+CELL
111 column=user:age, timestamp=2022-01-13T10:54:05.311, value=18
111 column=user:name, timestamp=2022-01-13T10:53:55.844, value=jack
333 column=user:age, timestamp=2022-01-13T10:55:41.442, value=25
333 column=user:name, timestamp=2022-01-13T10:55:41.442, value=mary
2 row(s)
Took 0.0309 seconds
hbase(main):041:0>
數(shù)據(jù)成功插入
第二步躺苦,在Phoenix中創(chuàng)建一個映射至HBase目標(biāo)表的視圖
注意:
1,Phoneix中創(chuàng)建的視圖名稱與HBase中映射的表名要相同
2产还,phoneix中創(chuàng)建視圖的字段名與與HBase中映射表的字段名要相同(注意大小寫)
1匹厘,在DBeaver中創(chuàng)建映射視圖
CREATE VIEW "hbase_test"(id varchar primary key, "user"."name" varchar, "user"."age" varchar);
2,在DBeaver查看視圖
SELECT * FROM "hbase_test"