hive on hbase 示例

hive on hbase 示例


--创建hive表,并映射hbase的表
 CREATE TABLE `test_db.hbase_employee`(                              
   `key` string COMMENT '',                                             
   `companycode` string COMMENT '',                                     
   `t_name` string COMMENT '',                                           
   `t_postid` string COMMENT '')                                          
 ROW FORMAT SERDE                                                       
   'org.apache.hadoop.hive.hbase.HBaseSerDe'                            
 STORED BY                                                              
   'org.apache.hadoop.hive.hbase.HBaseStorageHandler'                   
 WITH SERDEPROPERTIES (                                                 
   'hbase.columns.mapping'=':key,cf1:companycode,cf1:t_name,cf1:t_postid', 
   'serialization.format'='1')                                          
 TBLPROPERTIES (                                                        
   'bucketing_version'='2',                                             
   'hbase.table.name'='realtime_fee:hbase_employee')                                
;

#使用hbase shell工具查询
hbase shell
#查询有哪些表
hbase(main):002:0> list
TABLE
realtime_fee:hbase_employee
1 row(s) in 0.0710 seconds
#查询表描述
hbase(main):003:0> desc 'realtime_fee:hbase_employee'
Table realtime_fee:hbase_employee is ENABLED
realtime_fee:hbase_employee
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf1', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIO
NS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
1 row(s) in 0.1850 seconds
#查询表数据量
count 'realtime_fee:hbase_employee'
0 row(s) in 0.3330 seconds
=> 0

--hive写入数据到hbase表
insert into test_db.hbase_employee values ('1','01','one','10');
insert into test_db.hbase_employee values ('2','02','two','20');

--hive查询表数据
select * from test_db.hbase_employee;
+---------------------+-----------------------------+------------------------+--------------------------+
| hbase_employee.key  | hbase_employee.companycode  | hbase_employee.t_name  | hbase_employee.t_postid  |
+---------------------+-----------------------------+------------------------+--------------------------+
| 1                   | 01                          | one                    | 10                       |
| 2                   | 02                          | two                    | 20                       |
+---------------------+-----------------------------+------------------------+--------------------------+
2 rows selected (1.472 seconds)

--hive更新表数据 
insert overwrite table test_db.hbase_employee 
select '3','03','three','30'
union all 
select '2','04','four','40';

--hive查询更新之后的表数据
select * from test_db.hbase_employee;
+---------------------+-----------------------------+------------------------+--------------------------+
| hbase_employee.key  | hbase_employee.companycode  | hbase_employee.t_name  | hbase_employee.t_postid  |
+---------------------+-----------------------------+------------------------+--------------------------+
| 1                   | 01                          | one                    | 10                       |
| 2                   | 04                          | four                   | 40                       |
| 3                   | 03                          | three                  | 30                       |
+---------------------+-----------------------------+------------------------+--------------------------+
3 rows selected (0.928 seconds)


#hbase shell查询表数据 
count 'realtime_fee:hbase_employee'
3 row(s) in 0.0640 seconds
=> 3

scan 'realtime_fee:hbase_employee'
scan 'realtime_fee:hbase_employee'
ROW                                              COLUMN+CELL
 1                                               column=cf1:companycode, timestamp=1737367211730, value=01
 1                                               column=cf1:t_name, timestamp=1737367211730, value=one
 1                                               column=cf1:t_postid, timestamp=1737367211730, value=10
 2                                               column=cf1:companycode, timestamp=1737367948418, value=04
 2                                               column=cf1:t_name, timestamp=1737367948418, value=four
 2                                               column=cf1:t_postid, timestamp=1737367948418, value=40
 3                                               column=cf1:companycode, timestamp=1737367948418, value=03
 3                                               column=cf1:t_name, timestamp=1737367948418, value=three
 3                                               column=cf1:t_postid, timestamp=1737367948418, value=30
3 row(s) in 0.0610 seconds

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值