Hive的压缩【是优化手段之一】

hive的压缩使用的是工具压缩,跟存储格式自带压缩不是一回事儿。

HQL语句最终会被编译成Hadoop的Mapreduce job,因此hive的压缩设置,实际上就是对底层MR在处理数据时的压缩设置。

1)hive在map阶段压缩

map阶段的设置, 就是在MapReduce的shuffle阶段对mapper产生的中间结果数据压缩 。 在这个阶段,优先选择一个低CPU开销的算法。因为map阶段要将数据传递给reduce阶段,使用压缩可以提高传输效率。

hive-site.xml

<!-- 指定要不要开启中间压缩 -->
<property>
    <name>hive.exec.compress.intermediate</name>
    <value>false</value>
</property>

<!-- 指定中间压缩想要使用的压缩编码器(类文件) -->
<property>
    <name>hive.intermediate.compression.codec</name>
    <value/>
</property>

<!-- 指定压缩编码器中的那种压缩类型 -->
<property>
    <name>hive.intermediate.compression.type</name>
    <value/>
</property>

2)hive在reduce阶段的压缩
 

<!-- 指定要不要开启最终压缩。 -->
<property>
  <name>hive.exec.compress.output</name>
  <value>false</value>
</property>

注意:如果开启,默认使用中间压缩配置的压缩编码器和压缩类型

3)常见的压缩类型

企业中一般使用snappy和lzo进行压缩。

4)压缩编码器

5)实战一下

-- 开启中间压缩机制
hive (yhdb)> set hive.exec.compress.intermediate=true;
-- 设置中间压缩编码器
hive (yhdb)> set hive.intermediate.compression.codec=org.apache.hadoop.io.compress.DefaultCodec;
-- 设置压缩类型
hive (yhdb)> set hive.intermediate.compression.type=RECORD;
-- 开启reduce端的压缩机制
hive (yhdb)> set hive.exec.compress.output=true;
-- 创建表
create external table if not exists stocks_seq_2 (
track_time string,
url string,
session_id string,
referer string,
ip string,
end_user_id string,
city_id string
)
row format delimited
fields terminated by ','
stored as sequencefile;

--动态加载数据:
insert into stocks_seq_2 select * from stocks_1;

使用压缩后:16.71M

使用压缩前:19.37M

压缩工具如何判断好坏? 压缩比例高,解压速度快!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值