温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。


1.问题描述

CDH中默认不支持Lzo压缩编码,需要下载额外的Parcel包,才能让Hadoop相关组件如HDFS,Hive,Spark支持Lzo编码。

具体请参考:

​https://www.cloudera.com/documentation/enterprise/latest/topics/cm_mc_gpl_extras.html​


​https://www.cloudera.com/documentation/enterprise/latest/topics/cm_ig_install_gpl_extras.html#xd_583c10bfdbd326ba-3ca24a24-13d80143249--7ec6​

首先我在没做额外配置的情况下,生成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并执行上面命令:


如何在CDH中使用LZO压缩_hadoop

如何在CDH中使用LZO压缩_hive_02

如何在CDH中使用LZO压缩_hadoop_03

查询test_table中的数据:


如何在CDH中使用LZO压缩_hive_04

将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)

如何在CDH中使用LZO压缩_hive_05

通过Yarn的8088可以发现是因为找不到Lzo压缩编码:

Compression codec com.hadoop.compression.lzo.LzoCodec was not found.

如何在CDH中使用LZO压缩_hive_06


2.解决办法

通过Cloudera Manager的Parcel页面配置Lzo的Parcel包地址:

如何在CDH中使用LZO压缩_hive_07

注意:如果集群无法访问公网,需要提前下载好Parcel包并发布到httpd

下载->分配->激活


如何在CDH中使用LZO压缩_hive_08

如何在CDH中使用LZO压缩_hadoop_09

如何在CDH中使用LZO压缩_mapreduce_10

如何在CDH中使用LZO压缩_hadoop_11

如何在CDH中使用LZO压缩_hive_12

配置HDFS的压缩编码加入Lzo:

com.hadoop.compression.lzo.LzoCodec

com.hadoop.compression.lzo.LzopCodec

如何在CDH中使用LZO压缩_hadoop_13

如何在CDH中使用LZO压缩_hadoop_14

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

如何在CDH中使用LZO压缩_hadoop_15

如何在CDH中使用LZO压缩_hive_16

等待重启成功:


如何在CDH中使用LZO压缩_hive_17

再次插入数据到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;

插入成功:


如何在CDH中使用LZO压缩_hadoop_18

2.1 Hive验证

首先确认test_table2中的文件为Lzo格式:

如何在CDH中使用LZO压缩_hadoop_19

在Hive的beeline中进行测试:


如何在CDH中使用LZO压缩_mapreduce_20

如何在CDH中使用LZO压缩_mapreduce_21

Hive基于Lzo压缩文件运行正常。

2.2 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")


如何在CDH中使用LZO压缩_hadoop_22

SparkSQL基于Lzo压缩文件运行正常。


醉酒鞭名马,少年多浮夸! 岭南浣溪沙,呕吐酒肆下!挚友不肯放,数据玩的花!


温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。