Home  >  Article  >  Database  >  添加lzo for hive table

添加lzo for hive table

WBOY
WBOYOriginal
2016-06-07 16:29:161083browse

hive?hiveconf hive.exec.compress.output=true hiveconf mapred.output.compression.codec=com.hadoop.compression.lzo.LzopCodec 之后为其每个lzo块添加index: hadoop jar /usr/local/hadoop/lib/hadoop-lzo-0.4.15.jar com.hadoop.compression.lzo.Distr

hive?–hiveconf hive.exec.compress.output=true –hiveconf mapred.output.compression.codec=com.hadoop.compression.lzo.LzopCodec

之后为其每个lzo块添加index:

hadoop jar /usr/local/hadoop/lib/hadoop-lzo-0.4.15.jar com.hadoop.compression.lzo.DistributedLzoIndexer ?path/xxx.lzo ? ?注意(没有-jobconf mapred.output.compression.codec=com.hadoop.compression.lzo.LzopCodec选项只设置-jobconf mapred.output.compress=true 选项的话 reduce作业输出文件的格式为.lzo_deflate )

之所以要为其添加index的原理:

这样会按照block大小来切分块。(速度变快,但是多消耗cpu时间。map数目大量增加)

如果不对文件建立lzo索引则不会按照block来切分块

使用LZO过程会发现它有两种压缩编码可以使用,即LzoCodec和LzopCodec,下面说说它们区别:

  1. LzoCodec比LzopCodec更快, LzopCodec为了兼容LZOP程序添加了如?bytes signature, header等信息
  2. 如果使用?LzoCodec作为Reduce输出,则输出文件扩展名为”.lzo_deflate”,它无法被lzop读取;如果使用LzopCodec作为Reduce输出,则扩展名为”.lzo”,它可以被lzop读取
  3. 生成lzo index job的”DistributedLzoIndexer“无法为 LzoCodec,即 “.lzo_deflate”扩展名的文件创建index
  4. ”.lzo_deflate“文件无法作为MapReduce输入,”.LZO”文件则可以。
  5. 综上所述得出最佳实践:map输出的中间数据使用 LzoCodec,reduce输出使用 LzopCodec
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn