[Hive]Hive表文件压缩介绍

目录

 

压缩

(1)压缩概述

(2)开启Map输出阶段压缩

(3)开启Reduce输出阶段压缩

(4)创建表时指定压缩格式


压缩

(1)压缩概述

MR支持的压缩编码

 

为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器

 

压缩性能的比较

 

假如有一个表:

create table emp_t(

id int,

name String,

deptno int)

row format delimited

fields terminated by ','

collection items terminated by '-'

map keys terminated by ':'

stored as textfile;

 

(2)开启Map输出阶段压缩

开启map输出阶段压缩可以减少job中Map和Reduce task间数据传输量。具体配置如下:

案例实操:

开启hive中间传输数据压缩功能

set hive.exec.compress.intermediate=true;

开启mapreduce中map输出压缩功能

set mapreduce.map.output.compress=true;

设置mapreduce中map输出数据的压缩方式

set mapreduce.map.output.compress.codec=org.apache.hadoop.io.compress.SnappyCodec;

执行查询语句

select count(1) as name from emp_t;

(3)开启Reduce输出阶段压缩

当Hive将输出写入到表中时,输出内容同样可以进行压缩。属性hive.exec.compress.output控制着这个功能。用户可能需要保持默认设置文件中的默认值false,这样默认的输出就是非压缩的纯文本文件了。用户可以通过在查询语句或执行脚本中设置这个值为true,来开启输出结果压缩功能。

案例实操:

开启hive最终输出数据压缩功能,默认false

set hive.exec.compress.output=true;

开启mapreduce最终输出数据压缩,默认false

set mapreduce.output.fileoutputformat.compress=true;

设置mapreduce最终数据输出压缩方式,

默认:mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.DeflateCodec

set mapreduce.output.fileoutputformat.compress.codec =org.apache.hadoop.io.compress.SnappyCodec

设置mapreduce最终数据输出压缩为块压缩(NONE 、RECORD、BLOCK)

set mapreduce.output.fileoutputformat.compress.type=BLOCK;

刚创建表时,hdfs中没有文件

 

插入数据后插入数据,文件格式为snappy:

insert into emp_t(id,name,deptno)values(1,'zhangsan',1);

 

关闭mapreduce压缩后插入数据,文件格式为textfile:

insert into emp_t(id,name,deptno)values(2,'zhangsan',1);

 

(4)创建表时指定压缩格式

创建表时指定压缩格式和通过设置Reduce输出阶段压缩的功能一样。

create table emp_t1(

id int,

name String,

deptno int)

row format delimited

fields terminated by ','

collection items terminated by '-'

map keys terminated by ':'

STORED AS orc tblproperties ("orc.compress"="Snappy");

插入数据:

insert into emp_t1(id,name,deptno)values(2,'zhangsan',1);

查看HDFS的文件:

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值