hive和hbase整合

本文介绍了如何将Apache Hive 0.13.1与HBase 0.96.2进行整合,通过HBase客户端API实现数据交互。首先,将HBase库的jar包导入到Hive的lib目录,接着启动两者服务。然后,在Hive中创建表并添加分区,再通过中间表策略写入数据到HBase,最终成功验证了数据的写入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

hive和hbase整合使用hbase客服端API实现的

我这里使用的版本是apache-hive-0.13.1-bin.tar.gz和hbase-0.96.2-hadoop2.tar.gz
1.将hbase中lib目录中的ls hbase- 查出的jar包全部导入hive中的lib目录下,再将htrace-core-2.04.jar 查出来的包导入hive的lib目录下,如图
这里写图片描述

2.启动hive和hbase

3.建表

CREATE  TABLE pv (
rowid INT,year int,month int,day int,page string,count int
) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = "cf:year,cf:month,cf:day,cf:page,cf:count")
TBLPROPERTIES ("hbase.table.name" = "pv");

4.创建数据表

a.创建mylog

create external table mylog(remote_addr string,remote_user string,
                time_local string,request string,
                status string,body_bytes_sent string,
                http_referer string,http_user_agent string,
                http_x_forwarded_for string)
                partitioned by(year int,month int,day int)
                row format delimited
                fields terminated by ','
                lines terminated by '\n'
                stored as TEXTFILE;

b.添加分区
alter table mylog add partition(year=2017,month=08,day=30);
c.数据

192.168.22.1,-,30/Aug/2017:03:53:12,GET /mybigdata-0.0.1-SNAPSHOT/phone/huawei.html HTTP/1.0,304,0,-,Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0,-

d.创建中间表

create table moddle_t(key int,year int,month int,day int,page string,count int) row format delimited fields terminated by ',';

f.中间表写入数据

insert into table moddle_t select 1,year,month,day,request,100 from mylog;

e.向pv表写入数据

1.set hive.hbase.bulk=true;
2.insert into table pv select *from moddle_t;

成功后为:红线框中的数据
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值