10 Star 14 Fork 4

震秦 / hive-protobuf-serde

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Apache Hive Protobuf SerDe


##项目说明:

该项目用于 Hive 解析读取 Protobuf 序列化文件的一个组件.

##开发背景:

因为项目的不确定性, 加字段是常见的. 因此需要对于加了字段不需要改 Schama, 或者改 Schama 还能不影响老数据是紧迫需求. 这种对于 Schama 和数据都不影响的方式存储数据, 可以用 JSON, AVRO,Protobuf 等. JSON 存储序列化和反序列化开销大, 并存储也比较大. Avro 目前并不流行, 当然 Hive 默认是对 Avro 支持的. 而我们的 Bean 都是 Protobuf 定义的, 因此开发 Hive-protobuf-serde 来支持 Hive 对 Protobuf 数据建表, 并查询.

###优势:

序列化反序列化速度快, 序列化字节小, 增减字段对老数据兼容性好.

##Hive 建表:

CREATE  TABLE locations2 (
    location STRING,
    locCountry BIGINT,
    locProvince BIGINT,
    locCity BIGINT,
    cityLevel INT)
ROW FORMAT SERDE 'com.ivyft.hive.serde2.protobuf.ProtobufSerde'
STORED AS
INPUTFORMAT 'com.ivyft.hive.hadoop.IntLengthHeaderMr1InputFormat' 
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
TBLPROPERTIES ('hive.protobuf.class' = 'com.ivyft.hive.serde2.entity.Entities$Location')
SERDEPROPERTIES('hive.protobuf.class' = 'com.ivyft.hive.serde2.entity.Entities$Location') ;

##Protobuf 数据序列化

该项目内部有一个IntLengthHeaderFile类, 内部的 Reader 和 Writer 可以读写 Protobuf 类. 写时的规则为:

byte[] bytes = protobufObject.toByteArray();
outputstream.writeInt(bytes.length);
outputstream.write(bytes);

读时:

int length = inputstream.readInt();
byte[] bytes = new byte[length];
inputstream.read(bytes, 0, length);
protobufObject = ProtobufClass.parseFrom(bytes);

用IntLengthHeaderFile类完全可以做到如上. 并能利用 Hive-Protobuf-Serde 解析.

空文件

简介

Hive 对 Protobuf 序列化文件读取 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/zhzhenqin/hive-protobuf-serde.git
git@gitee.com:zhzhenqin/hive-protobuf-serde.git
zhzhenqin
hive-protobuf-serde
hive-protobuf-serde
master

搜索帮助