4.如何在CDH中使用LZO压缩

4.1 问题概述

  • CDH中默认不支持Lzo压缩编码,需要下载额外的Parcel包,才能让Hadoop相关组件如HDFS,Hive,Spark支持Lzo编码。
  • 首先在没做额外配置的情况下,生成Lzo文件并读取。
    • 在Hive中创建两张表,test_table和test_table2,test_table是文本文件的表,test_table2是Lzo压缩编码的表。
    • 如下:
create  external table test_table
(
s1  string,
s2  string
)
row  format delimited fields terminated by '#'
location  '/lilei/test_table';

insert  into test_table values('1','a'),('2','b');

create  external table test_table2
(
s1  string,
s2  string
)
row  format delimited fields terminated by '#'
location  '/lilei/test_table2';
  • 通过beeline访问Hive并执行上面命令
  • 查询test_table中的数据
  • 将test_table中的数据插入到test_table2,并设置输出文件为lzo压缩
set  mapreduce.output.fileoutputformat.compress.codec=com.hadoop.compression.lzo.LzoCodec;
set  hive.exec.compress.output=true;
set  mapreduce.output.fileoutputformat.compress=true;
set  mapreduce.output.fileoutputformat.compress.type=BLOCK;

insert  overwrite table test_table2 select * from test_table;
  • 在Hive中执行报错如下:
Error:Error while processing statement: FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask (state=08S01,code=2)
  • 通过Yarn的8088可以发现是因为找不到Lzo压缩编码:
Compression codec com.hadoop.compression.lzo.LzoCodec was not found.

4.2 解决方法

  • 通过Cloudera Manager的Parcel页面配置Lzo的Parcel包地址:
  • 注意:如果集群无法访问公网,需要提前下载好Parcel包并发布到httpd
  • 下载->分配->激活


  • 配置HDFS的压缩编码加入Lzo:
com.hadoop.compression.lzo.LzoCodec
com.hadoop.compression.lzo.LzopCodec


  • 保存更改,部署客户端配置,重启整个集群。

  • 等待重启成功:
  • 再次插入数据到test_table2,设置为Lzo编码格式:
set  mapreduce.output.fileoutputformat.compress.codec=com.hadoop.compression.lzo.LzoCodec;
set  hive.exec.compress.output=true;
set mapreduce.output.fileoutputformat.compress=true;
set  mapreduce.output.fileoutputformat.compress.type=BLOCK;
 
insert  overwrite table test_table2 select * from test_table;
  • Hive验证
    • 首先确认test_table2中的文件为Lzo格式
    • 在Hive的beeline中进行测试
    • 确认Hive基于Lzo压缩文件运行正常
  • Spark SQL验证
var  textFile=sc.textFile("hdfs://ip-172-31-8-141:8020/lilei/test_table2/000000_0.lzo_deflate")

textFile.count()

sqlContext.sql("select  * from test_table2")
  • 确认SparkSQL基于Lzo压缩文件运行正常

大数据视频推荐:
CSDN
大数据语音推荐:
企业级大数据技术应用
大数据机器学习案例之推荐系统
自然语言处理
大数据基础
人工智能:深度学习入门到精通

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值