今天研究了一下hive里面的压缩来达到节省空间的目的。
说到压缩就不得不介绍下hive的常见的文件格式,textfile,sequencefile,rcffile,orcfile
[ ] textfile
hive 中默认格式,特点是占用空间大,压缩之后不支持切分
[ ] sequencefile
二进制存储格式
[ ] fcfile
数据按行分块 每块按照列存储
[ ] orcfile
数据按行分块 每块按照列存储 ,orc( Optimized RCFile)他是RCFile的plus版,支持 lzo snappy 压缩(这个是今天的主角)
主要操作(这里主要介绍关键点,默认是了解datax操作和了解hadoop知识)
之前我们用的是textfile这种格式存储
CREATE TABLE `t_user_active`(
`id` string COMMENT '主键ID',
`user_id` string COMMENT '用户ID',
`user_name` string COMMENT '用户名称',
`channel_id` string COMMENT '渠道号id',
`use_count` int COMMENT '使用个数据',
`create_by` string COMMENT '创建者ID',
`create_date` string COMMENT '创建时间',
`update_by` string COMMENT '更新者ID',
`update_date` timestamp COMMENT '更新时间'
)
PARTITIONED BY (
`create_data` string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE;
修改压缩格式是这样的,使用ocr的格式存储,开启snappy压缩
CREATE TABLE `t_user_active`(
`id` string COMMENT '主键ID',
`user_id` string COMMENT '用户ID',
`user_name` string COMMENT '用户名称',
`channel_id` string COMMENT '渠道号id',
`use_count` int COMMENT '使用个数据',
`create_by` string COMMENT '创建者ID',
`create_date` string COMMENT '创建时间',
`update_by` string COMMENT '更新者ID',
`update_date` t