hive连接hbase

hive中

创建hive中写入hbase有关的表:(创建时hbase中有对应的命名空间Test

hive> CREATE TABLE hbase_table_4(key int, value string) 
    > -- 死格式,存储的时候使用下面的类
    > STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
    > -- hbase的键和值与hive表的对应关系;自动对应列的关系;第一列对应第一列;cf1:(列族)
    > WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
    > -- hive中的表名对hbase中的表名如何对应
    > TBLPROPERTIES ("hbase.table.name" = "Test:hbase_table_4", "hbase.mapred.output.outputtable" = "hbase_table_4");
2020-07-29 16:01:15,507 INFO  [86c0a64a-2708-4a57-8345-e6a526c7aa05 main] zookeeper.RecoverableZooKeeper: Process identifier=hconnection-0x355b53cc connecting to ZooKeeper ensemble=node7-1:2181,node7-2:2181,node7-3:2181
2020-07-29 16:01:18,249 INFO  [86c0a64a-2708-4a57-8345-e6a526c7aa05 main] client.HBaseAdmin: Operation: CREATE, Table Name: Test:hbase_table_4 completed
OK
Time taken: 3.651 seconds

查看一下表:

hive> show tables;
OK
a_region
a_users
hbase_table_4
Time taken: 0.142 seconds, Fetched: 3 row(s)

在表里插入数据,就这一句话,下面是运行出现的:insert into hbase_table_4 values (1,'aa');

hive> insert into hbase_table_4 values (1,'aa');
Query ID = root_20200729160304_2354ea49-cebb-4910-bead-621cf77891f0
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
2020-07-29 16:03:11,028 WARN  [86c0a64a-2708-4a57-8345-e6a526c7aa05 main] mapreduce.TableMapReduceUtil: The addDependencyJars(Configuration, Class<?>...) method has been deprecated since it is easy to use incorrectly. Most users should rely on addDependencyJars(Job) instead. See HBASE-8386 for more details.
2020-07-29 16:03:11,032 WARN  [86c0a64a-2708-4a57-8345-e6a526c7aa05 main] mapreduce.TableMapReduceUtil: The addDependencyJars(Configuration, Class<?>...) method has been deprecated since it is easy to use incorrectly. Most users should rely on addDependencyJars(Job) instead. See HBASE-8386 for more details.
2020-07-29 16:03:13,695 INFO  [86c0a64a-2708-4a57-8345-e6a526c7aa05 main] zookeeper.RecoverableZooKeeper: Process identifier=hconnection-0x7156f8cf connecting to ZooKeeper ensemble=node7-1:2181,node7-2:2181,node7-3:2181
Starting Job = job_1595982612570_0001, Tracking URL = http://node7-1:8088/proxy/application_1595982612570_0001/
Kill Command = /data/hadoop/hadoop/bin/mapred job  -kill job_1595982612570_0001
Hadoop job information for Stage-2: number of mappers: 1; number of reducers: 0
2020-07-29 16:03:55,720 Stage-2 map = 0%,  reduce = 0%
2020-07-29 16:04:26,717 Stage-2 map = 100%,  reduce = 0%, Cumulative CPU 8.26 sec
MapReduce Total cumulative CPU time: 8 seconds 260 msec
Ended Job = job_1595982612570_0001
MapReduce Jobs Launched: 
Stage-Stage-2: Map: 1   Cumulative CPU: 8.26 sec   HDFS Read: 13263 HDFS Write: 0 SUCCESS
Total MapReduce CPU Time Spent: 8 seconds 260 msec
OK
Time taken: 84.132 seconds
hive> insert into hbase_table_4 values (2,'bb');
Query ID = root_20200729160428_37f516ac-bb55-4f09-b27d-d713a8b5c96a
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
2020-07-29 16:04:31,426 WARN  [86c0a64a-2708-4a57-8345-e6a526c7aa05 main] mapreduce.TableMapReduceUtil: The addDependencyJars(Configuration, Class<?>...) method has been deprecated since it is easy to use incorrectly. Most users should rely on addDependencyJars(Job) instead. See HBASE-8386 for more details.
2020-07-29 16:04:31,439 WARN  [86c0a64a-2708-4a57-8345-e6a526c7aa05 main] mapreduce.TableMapReduceUtil: The addDependencyJars(Configuration, Class<?>...) method has been deprecated since it is easy to use incorrectly. Most users should rely on addDependencyJars(Job) instead. See HBASE-8386 for more details.
2020-07-29 16:04:31,783 INFO  [86c0a64a-2708-4a57-8345-e6a526c7aa05 main] zookeeper.RecoverableZooKeeper: Process identifier=hconnection-0x56afbace connecting to ZooKeeper ensemble=node7-1:2181,node7-2:2181,node7-3:2181
Starting Job = job_1595982612570_0002, Tracking URL = http://node7-1:8088/proxy/application_1595982612570_0002/
Kill Command = /data/hadoop/hadoop/bin/mapred job  -kill job_1595982612570_0002
Hadoop job information for Stage-2: number of mappers: 1; number of reducers: 0
2020-07-29 16:04:55,751 Stage-2 map = 0%,  reduce = 0%
2020-07-29 16:05:15,909 Stage-2 map = 100%,  reduce = 0%, Cumulative CPU 8.26 sec
MapReduce Total cumulative CPU time: 8 seconds 260 msec
Ended Job = job_1595982612570_0002
MapReduce Jobs Launched: 
Stage-Stage-2: Map: 1   Cumulative CPU: 8.26 sec   HDFS Read: 13245 HDFS Write: 0 SUCCESS
Total MapReduce CPU Time Spent: 8 seconds 260 msec
OK
Time taken: 48.696 seconds

hbase中:

看命名空间

hbase(main):080:0* list_namespace
NAMESPACE                                                                          
Test                                                                               
default                                                                            
hbase                                                                              
mydata                                                                             
usercenter                                                                         
5 row(s)
Took 0.1455 seconds 

查看表里数据:

hbase(main):081:0> scan 'Test:hbase_table_4'
ROW                   COLUMN+CELL                                                  
 1                    column=cf1:val, timestamp=1596009919626, value=aa            
 2                    column=cf1:val, timestamp=1596009969247, value=bb            
2 row(s)
Took 0.9060 seconds 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值