hive结果及中间结果压缩
来源:互联网 发布:nginx 绑定域名 编辑:程序博客网 时间:2024/04/29 11:16
转自:
hadoop中常见的压缩格式及特性如下:
压缩格式工具算法文件扩展名多文件可分割性DEFLATE*无DEFLATE.deflate不不GzipgzipDEFLATE.gz不不ZIPzipDEFLATE.zip是是,在文件范围内bzip2bzip2bzip2.bz2不是LZOlzopLZO.lzo不不首先hive作业结果最好使用sequencefile,因为textfile是没有压缩的。
使用sequencefile很简单,只要在建表的时候用:
stored as seqeuncefile
声明就可以。
注意如果是用create table as语句,它会读取hive-site.xml里的默认格式(默认是textfile)。
配置如下:
hadoop-site.xml配置:
<property> <name>mapred.output.compression.type</name> <value>BLOCK</value> <description> </description></property>
<property> <name>io.seqfile.compressioin.type</name> <value>BLOCK</value> <description> </description></property>
然后配置:
<property> <name>mapred.output.compress</name> <value>true</value> <description>Should the job outputs be compressed? </description></property><property> <name>mapred.output.compression.codec</name> <value>org.apache.hadoop.io.compress.LzoCodec</value> <description>If the job outputs are compressed, how should they be compressed? </description></property>或在hive-site.xml中配置:
<property> <name>hive.exec.compress.output</name> <value>true</value> <description>Should the job outputs be compressed? </description></property>之后我们就可以配置输出结果的压缩方式了,默认是使用zlib,即org.apache.hadoop.io.compress.DefaultCodec。
我们可以改成其他的,比如速度比较快的lzo。
需要注意的是,lzo在0.19.1中是存在的,但是在0.20之后,因为许可证问题被移除了,是需要单独安装的。
首先需要添加lzo codec,在hadoop-site.xml中添加:
<property> <name>io.compression.codecs</name> <value>org.apache.hadoop.io.compress.DefaultCodec,org.apache.hadoop.io.compress.GzipCodec,org.apache.hadoop.io.compress.BZip2Codec,org.apache.hadoop.io.compress.LzoCodec</value> <description>A list of the compression codec classes that can be used for compression/decompression.</description></property>
其他的压缩配置按照上面的写就OK。
配置完以后,可以在job.xml中查看运行的作业的配置是否启用了压缩,也可以使用
hadoop fs -cat 输出结果文件 | more
来查看是否启用压缩。因为输出结果文件的文件头是标注了文件的格式的,如key和value的类名,以及是否压缩。如果启用压缩,你能看到类似下面的输出:
SEQ"org.apache.hadoop.io.BytesWritableorg.apache.hadoop.io.Text*org.apache.hadoop.io.compress.DefaultCodec...
上面讲的都是输出结果的压缩,map的中间结果也可以启用压缩,而且中间结果对输出结果是没有影响的:
hadoop-site.xml中:
<property> <name>mapred.compress.map.output</name> <value>true</value> <description>Should the outputs of the maps be compressed before being sent across the network. Uses SequenceFile compression. </description></property><property> <name>mapred.map.output.compression.codec</name> <value>org.apache.hadoop.io.compress.LzoCodec</value> <description>If the map outputs are compressed, how should they be compressed? </description></property>
也可以hive-site.xml中配置:
<property> <name>hive.exec.compress.intermediate</name> <value>true</value> <description>Should the outputs of the maps be compressed before being sent across the network. Uses SequenceFile compression. </description></property><property> <name>hive.intermediate.compression.codec</name> <value>org.apache.hadoop.io.compress.LzoCodec</value> <description>If the map outputs are compressed, how should they be compressed? </description></property>
或者直接在HIVE脚本中写:
set hive.exec.compress.intermediate=true;
set hive.intermediate.compression.codec="org.apache.hadoop.io.compress.LzoCodec";
中间结果的压缩,建议采用lzo,因为它速度比较快,不像其他压缩方式比较耗CPU。
当然,如果启用了lzo,也会有上面说的许可证的问题,要保证你的集群机器都单独安装了lzo压缩包。
- hive结果及中间结果压缩
- hive中间结果和结果的压缩
- hive 压缩 最终结果 中间结果
- 记录一下Hive中间和最终结果压缩
- hive 查询结果压缩
- hive共享中间结果集
- Hive 优化之 共享中间结果集
- C++中间结果溢出
- 图片压缩方案预研及结果
- hive结果导出
- hive 客户端结果乱码
- hive查询结果导出
- pg如何保存中间结果
- hive使用技巧(二)——共享中间结果集
- hive +hbase 得不到返回结果
- hive依赖oracle执行结果
- Hive查询结果输出文件
- 结果
- JQuery操作option的添加、删除、取值
- WPF 第三方资源
- javascript DOM编程艺术学习笔记(1)重写getElementsByClassName(class)方法
- hadoop黑名单机制
- JS编码
- hive结果及中间结果压缩
- 1010. 一元多项式求导 (25)
- Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- Gson与JSONObject
- 基于《知网》的词汇语义相似度计算(上)(作者:刘群 李素建)
- hadoop容错性分析
- javascript DOM编程艺术学习笔记(2)图片库例子:
- 自动编号
- 57.1万报考 四川今年高考人数创新高