使用Hive来访问HBase

启动hive,进入hive的终端
hive --auxpath /opt/hive/lib/hive-hbase-handler-2.1.0.jar,/opt/hive/lib/zookeeper-3.4.6.jar --hiveconf hbase.master=hadoop01:16010 --hiveconf hbase.zookeeper.quorum=hadoop01,hadoop02,hadoop03
在Hive里面操作HBase
创建一张表:
如果hbase中不存在该表
我们只能在hive中使用创建内部表的方式,来创建一张表,同会在hbase中也会创建相关的表。
eg.
create table h2hb_1(
id int,
name string,
age int
)row format delimited
fields terminated by ','
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with serdeproperties (
"hbase.columns.mapping" = ":key,cf:name,cf:age",
"hbase.table.name" = "t"
);
在hive中创建了一张表h2hb_1,有三列内容id, name, age,同时映射到hbase中的表t,其中id对应行健
name对应hbase中列族cf中的name,age同理
如果hbase中已经存在该表
如果使用上述建表语句创建的时候,则会报错,因为在hbase中已经存在了一张表为t,所以这时只能创建外部表去映射hbase中的一张表。
create external table h2hb_2
(id int,
name string,
age int
)row format delimited
fields terminated by ','
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with serdeproperties (
"hbase.columns.mapping" = ":key,cf:name,cf:age",
"hbase.table.name" = "t"
);
我们即可对hbase中的表,使用hql来进行常见的分析操作,比较便利。

猜你喜欢

转载自blog.csdn.net/kaaosidao/article/details/78242235