Apache Hive 存储方式、压缩格式
简介:
Apache hive 存储方式跟压缩格式!
1、Text File
hive> create external table tab_textfile (
host string comment 'client ip address',
local_time string comment 'client access time',
api string comment 'request api',
request_type string comment 'request method, http version',
http_code int, body_bytes int, request_body map<string, string>,
referer string, user_agent string, upstr string, response_time string, request_time string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' COLLECTION ITEMS TERMINATED BY '&' MAP KEYS TERMINATED BY '=';
OK
Time taken: 0.162 seconds
# 创建一张 Text File 存储格式、不压缩的外部表
hive> load data local inpath '/data/logs/api/201711/tvlog_20171101/bftvapi.20171101.log' overwrite into table tab_textfile;
Loading data to table tmpdb.tab_textfile
OK
Time taken: 1015.974 seconds
# 原始文件 9.8G,加载到该表中需要花费 1015.974 秒 ( 这里可以优化,不使用 load 指令,直接 put 文件到数据表目录 )
hive> select count(*) from tab_textfile;
...
Stage-Stage-: Map: Reduce: Cumulative CPU: 269.51 sec HDFS Read: HDFS Write: SUCCESS
Total MapReduce CPU Time Spent: minutes seconds msec
OK Time taken: 95.68 seconds, Fetched: row(s)
# 总共 27199202 行数据,用时 95.68 秒
# 优化点:set [ hive.exec.reducers.bytes.per.reducer=<number>, hive.exec.reducers.max=<number>, mapreduce.job.reduces=<number> ]
2、ORC File
# 官方文档:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ORC
# ORC文档:https://orc.apache.org/docs
hive> create external table tab_orcfile (
host string comment 'client ip address',
local_time string comment 'client access time',
api string comment 'request api',
request_type string comment 'request method, http version',
http_code int, body_bytes int, request_body map<string, string>,
referer string, user_agent string, upstr string, response_time string, request_time string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' COLLECTION ITEMS TERMINATED BY '&' MAP KEYS TERMINATED BY '='
STORED AS ORC tblproperties ("orc.compress"="NONE");
OK
Time taken: 0.058 seconds
# 创建一张 ORC File 存储格式、不压缩的外部表
hive> insert overwrite table tab_orcfile select * from tab_textfile;
...
Stage-Stage-: Map: Cumulative CPU: 2290.24 sec HDFS Read: HDFS Write: SUCCESS
Total MapReduce CPU Time Spent: minutes seconds msec
OK
Time taken: 289.954 seconds
# 向 tab_orcfile 中加载数据,注意:ORC File 不能直接 load data !!!
# 可以先创建 Text File 的临时表,将数据手动上传到该表指定目录,然后转换成 ORC File 格式。
hive> select count(*) from tab_orcfile;
OK Time taken: 2.555 seconds, Fetched: row(s)
# 额,同样的语句,上面执行花费 95.68 秒,现在只要 2.555 秒。
# 换一种方式测试,先查 tab_orcfile 表,然后再查 tab_textfile 表。
hive> select count(host) from tab_orcfile;
...
Stage-Stage-: Map: Reduce: Cumulative CPU: 81.02 sec HDFS Read: HDFS Write: SUCCESS
Total MapReduce CPU Time Spent: minutes seconds msec
OK Time taken: 33.55 seconds, Fetched: row(s)
# ORC File 花费 33.55 秒
hive> select count(host) from tab_textfile;
...
Stage-Stage-: Map: Reduce: Cumulative CPU: 349.77 sec HDFS Read: HDFS Write: SUCCESS
Total MapReduce CPU Time Spent: minutes seconds msec
OK Time taken: 87.308 seconds, Fetched: row(s)
# Text File 花费 87.308 秒,高下立见!
3、启用压缩
# ORC 文档:https://orc.apache.org/docs/hive-config.html
hive> create external table tab_orcfile_zlib (
host string comment 'client ip address',
local_time string comment 'client access time',
api string comment 'request api',
request_type string comment 'request method, http version',
http_code int, body_bytes int, request_body map<string, string>,
referer string, user_agent string, upstr string, response_time string, request_time string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' COLLECTION ITEMS TERMINATED BY '&' MAP KEYS TERMINATED BY '='
STORED AS ORC;
# 默认的 ORC 压缩方式为 ZLIB,还支持 LZO、SNAPPY 等
hive> insert overwrite table tab_orcfile_zlib select * from tab_textfile;
...
Stage-Stage-: Map: Cumulative CPU: 2344.68 sec HDFS Read: HDFS Write: SUCCESS
Total MapReduce CPU Time Spent: minutes seconds msec
OK
Time taken: 299.204 seconds
# 数据加载完成
hive> select count(host) from tab_orcfile_zlib;
...
Stage-Stage-: Map: Reduce: Cumulative CPU: 43.66 sec HDFS Read: HDFS Write: SUCCESS
Total MapReduce CPU Time Spent: seconds msec
OK Time taken: 31.369 seconds, Fetched: row(s)
# 查询速度不受影响
hive> dfs -ls -h /user/hive/warehouse/tmpdb.db/tab_orcfile_zlib/
Found items
-rwxrwxrwx root supergroup 24.6 M -- : /user/hive/warehouse/tmpdb.db/tab_orcfile_zlib/000000_0
-rwxrwxrwx root supergroup 23.0 M -- : /user/hive/warehouse/tmpdb.db/tab_orcfile_zlib/000001_0
-rwxrwxrwx root supergroup 25.9 M -- : /user/hive/warehouse/tmpdb.db/tab_orcfile_zlib/000002_0
-rwxrwxrwx root supergroup 26.5 M -- : /user/hive/warehouse/tmpdb.db/tab_orcfile_zlib/000003_0
# 总共分成 39 个文件,每个平均 25M,总过不到 1G,原始文件 9.8G,这压缩比如何 ?
Apache Hive 存储方式、压缩格式的更多相关文章
- Hive 表数据的存储和压缩格式
SerDe * 按行存储 * 按列存储 file_format: : | SEQUENCEFILE 序列化(行存储) | TEXTFILE 文本格式(行存储)- (Default, depending ...
- Hadoop_常用存储与压缩格式
HDFS文件格式 file_format: TEXTFILE 默认格式 RCFILE hive 0.6.0 和以后的版本 ORC hive 0.11.0 和以后的版本 PARQUET hive 0.1 ...
- Hive支持的文件格式和压缩格式及各自特点
Hive中的文件格式 1-TEXTFILE 文本格式,Hive的默认格式,数据不压缩,磁盘开销大.数据解析开销大. 对应的hive API为:org.apache.hadoop.mapred.Text ...
- 一文彻底搞懂Hive的数据存储与压缩
目录 行存储与列存储 行存储的特点 列存储的特点 常见的数据格式 TextFile SequenceFile RCfile ORCfile 格式 数据访问 Parquet 测试 准备测试数据 存储空间 ...
- hive 压缩全解读(hive表存储格式以及外部表直接加载压缩格式数据);HADOOP存储数据压缩方案对比(LZO,gz,ORC)
数据做压缩和解压缩会增加CPU的开销,但可以最大程度的减少文件所需的磁盘空间和网络I/O的开销,所以最好对那些I/O密集型的作业使用数据压缩,cpu密集型,使用压缩反而会降低性能. 而hive中间结果 ...
- Hive压缩格式
TextFile Hive数据表的默认格式,存储方式:行存储. 可使用Gzip,Bzip2等压缩算法压缩,压缩后的文件不支持split 但在反序列化过程中,必须逐个字符判断是不是分隔符和行结束符,因此 ...
- Hive(十一)【压缩、存储】
目录 一.Hadoop的压缩配置 1.MR支持的压缩编码 2.压缩参数配置 3.开启Mapper输出阶段压缩 4.开启Reduceer输出阶段 二.文件存储 1.列式存储和行式存储 2.TextFil ...
- 浓缩的才是精华:浅析GIF格式图片的存储和压缩
成文迪, 在Web前端摸爬滚打的码农一枚,对技术充满热情的菜鸟,致力为手Q的建设添砖加瓦. GIF格式的历史 GIF(Graphics Interchange Format)原义是"图像互换 ...
- 【腾讯Bugly干货分享】舞动的表情包——浅析GIF格式图片的存储和压缩
本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/v0pffOhjFWnVbU2lXjuEmw 导语 G ...
随机推荐
- 使用Apriori进行关联分析(一)
大型超市有海量交易数据,我们可以通过聚类算法寻找购买相似物品的人群,从而为特定人群提供更具个性化的服务.但是对于超市来讲,更有价值的是如何找出商品的隐藏关联,从而打包促销,以增加营业收入.其中最经典的 ...
- RAC4——架构和变化
1.RAC的架构 2.由单实例变RAC的变化 1.SGA的变化: 和传统的单实例相比,RAC 实例中SGA最显著的变化时多了一个GRD(Global resource directory)部分. ...
- Spring Boot 整合 FastDFS 客户端
原文地址:Spring Boot 整合 FastDFS 客户端 博客地址:http://www.extlight.com 一.前言 前两篇介绍整体上介绍了通过 Nginx 和 FastDFS 的整合来 ...
- 【jmeter】jmeter测试手机app的服务器压力
具体步骤: 1.电脑启动jmeter 2.jmeter在测试计划新建线程组. 3.在工作台新建http代理服务器 4.配置HTTP代理服务器 5.设置IE代理到本地 6.手机wifi设置代理连接到PC ...
- Windows 2003扩充磁盘空间
diskpartlist volumeselect volume 1 (选择需要扩充空间的分区)extend size=409600 (单位为MB)
- 1、zookeeper集群安装
前提准备3台centos7.0虚拟机 c7003:192.168.70.103 c7004:192.168.70.104 c7005:192.168.70.105 并在三台虚拟机上配置hosts为 1 ...
- R语言学习——欧拉计划(1)Multiples of 3 and 5
[题目一]If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. ...
- airtest IDE问题汇总
FAQ 1.同一个脚本,使用IDE可以运行,使用命令行运行报错 原因:曾经开启过anyproxy代理,添加过HTTP_PROXY环境变量,将其取消即可 unset HTTP_PROXY https:/ ...
- 关于clearfix和clear的研究
今天领导跟我说到这个问题,我上网找了些资料,已转载一篇文章到本博客(后一篇),摘自百度文库. ps:还有一种写法就是: CSS代码: .clearfix:after { content: " ...
- unbound域名解析
安装unbound服务 # yum install unbound -y 开启服务 linux系统如何查看命令属于哪一个安装包 # yum provides */netstat 安装netstat命令 ...