SerDe

* 按行存储
* 按列存储 file_format:
:
| SEQUENCEFILE 序列化(行存储)
| TEXTFILE 文本格式(行存储)- (Default, depending on hive.default.fileformat configuration)
| RCFILE 列式存储文件(列存储)- (Note: Available in Hive 0.6.0 and later)
| ORC 常用 优化列式存储文件(列存储)- (Note: Available in Hive 0.11.0 and later)
| PARQUET 常用 (列存储)- (Note: Available in Hive 0.13.0 and later)
| AVRO - (Note: Available in Hive 0.14.0 and later)
| INPUTFORMAT input_format_classname OUTPUTFORMAT output_format_classname



ORC列存储结构如图所示,个人理解:每一个字段存为一列,index data 保存了最大值和最小值,只有当索引范围合适时,才去扫描对应的列数据查找匹配项

As shown in the diagram, each stripe in an ORC file holds index data, row data, and a stripe footer.

The stripe footer contains a directory of stream locations. Row data is used in table scans.

Index data includes min and max values for each column and the row positions within each column.索引数据包含了对应的 列(column)数据 的最大值和最小值,以及列中数据的相应行的位置。 Row index entries provide offsets that enable seeking to the right compression block and byte within a decompressed block. Note that ORC indexes are used only for the selection of stripes and row groups and not for answering queries.

来自 hortonworks 的性能评估

二、各种数据存储格式比较

For example, creating an ORC stored table without compression:

官网例子

create table Addresses (
name string,
street string,
city string,
state string,
zip int
) stored as orc tblproperties ("orc.compress"="NONE");

个人测试用例:TEXTFILE

create table bf_log(
user_ip string,
a string,
time string,
get2host string,
status1 string,
status2 string,
b string,
from_url string,
equipment_info string,
c string,
url_now string
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' stored as TEXTFILE;

导入数据

load data local inpath '/opt/datas/xxx.log' into table bf_log;

数据大小

2.0 M  /user/hive/warehouse/bf_log_orc/moodle.ibeifeng.access.log

使用 ORC 存储

create table bf_log_orc(
user_ip string,
a string,
time string,
get2host string,
status1 string,
status2 string,
b string,
from_url string,
equipment_info string,
c string,
url_now string
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' stored as orc;

导入数据

insert into table bf_log_orc select * from bf_log;

数据大小

62.5 K  /user/hive/warehouse/bf_log_orc/000000_0

使用 PARQUET

create table bf_log_parquet(
user_ip string,
a string,
time string,
get2host string,
status1 string,
status2 string,
b string,
from_url string,
equipment_info string,
c string,
url_now string
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' stored as PARQUET;

导入数据

insert into table bf_log_parquet select * from bf_log;

数据大小

360.1 K  /user/hive/warehouse/bf_log_parquet/000000_0

三、进行数据文件的压缩(主要只支持三种,详情见底部图片)

1.查看支持的数据压缩格式

cen@hostname-ubuntu:/opt/softwares/hadoop-2.8.0$ bin/hadoop checknative
17/07/17 05:34:32 INFO bzip2.Bzip2Factory: Successfully loaded & initialized native-bzip2 library system-native
17/07/17 05:34:32 INFO zlib.ZlibFactory: Successfully loaded & initialized native-zlib library
Native library checking:
hadoop: true /opt/softwares/hadoop-2.8.0/lib/native/libhadoop.so.1.0.0
zlib: true /lib/x86_64-linux-gnu/libz.so.1
snappy: true /usr/lib/x86_64-linux-gnu/libsnappy.so.1
lz4: true revision:10301
bzip2: true /lib/x86_64-linux-gnu/libbz2.so.1
openssl: true /usr/lib/x86_64-linux-gnu/libcrypto.so

2.使用 snappy 压缩

create table bf_log_orc_snappy(
user_ip string,
a string,
time string,
get2host string,
status1 string,
status2 string,
b string,
from_url string,
equipment_info string,
c string,
url_now string
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' stored as PARQUET tblproperties ("orc.compress"="snappy");

导入数据

insert into table bf_log_orc_snappy select * from bf_log;

数据大小

360.1 K  /user/hive/warehouse/bf_log_orc_snappy/000000_0
#!!!什么?居然搞大了,为什么?
#因为原本默认使用的是 ZLIB (接近bzip2)压缩



图片来源

四、总结

最常用的解决方案:

  • 数据格式:orc | parquet
  • 压缩格式:sanppy

Hive 表数据的存储和压缩格式的更多相关文章

  1. hive-hbase-handler方式导入hive表数据到hbase表中

    Hive与HBase的整合功能的实现是利用两者本身对外的API接口互相进行通信,相互通信主要是依靠hive-hbase-handler.jar工具类 : hive-hbase-handler.jar在 ...

  2. hive 将hive表数据查询出来转为json对象和json数组输出

    一.将hive表数据查询出来转为json对象输出 1.将查询出来的数据转为一行一行,并指定分割符的数据 2.使用UDF函数,将每一行数据作为string传入UDF函数中转换为json再返回 1.准备数 ...

  3. Hadoop_常用存储与压缩格式

    HDFS文件格式 file_format: TEXTFILE 默认格式 RCFILE hive 0.6.0 和以后的版本 ORC hive 0.11.0 和以后的版本 PARQUET hive 0.1 ...

  4. hive表数据导出到csv乱码原因及解决方案

    转载自http://blog.csdn.net/lgdlxc/article/details/42126225 Hive表中的数据使用hive - e"select * from table ...

  5. [源码分享] HIVE表数据量统计&邮件

    概要: 计算HIVE BI库下每天数据表总大小及增量 输出: 总大小:xxxG 日同比新增数据量:xxxG 周同比新增数据量:xxxG 月同比新增数据量:xxxG 总表数:xxx 日新增表数:xxx ...

  6. MySQL-5.7设置InnoDB表数据文件存储位置

    1.表空间 Innodb存储引擎可将所有数据存放于ibdata*的共享表空间,也可将每张表存放于独立的.ibd文件的独立表空间. 共享表空间以及独立表空间都是针对数据的存储方式而言的. 共享表空间: ...

  7. Hive表数据同步到es

    1.首先服务器节点,进入到对应的数据库.2. 然后找到要同步的表,show create table + 表名查看一下或者自己可以新建一个表,用来测试原表,如下 CREATE TABLE `wb_tm ...

  8. MySQL的nnodb引擎表数据分区存储

    Symlinks are fully supported only for MyISAM tables. 对应Innodb引擎数据文件放到其他目录 mysql> SHOW VARIABLES L ...

  9. Hive表数据导出

    方式一: hadoop命令导出 hadoop fs -get hdfs://hadoop000:8020/data/page_views2 pv2  方式二:通过insert...directory导 ...

随机推荐

  1. HTTP杂记

    HTTP请求中的浏览器Timing信息: stalled:浏览器发出请求到这个请求可以发出的等待时间 proxy negotiation: 代理协商的时间 request sent:请求的第一个字节发 ...

  2. iphone 微信下浏览器中数字去除下划线

    在开发iphone应用程序的时候,safari下手机号码默认是有下划线的,通过下面的方法就可以去掉: <meta name="format-detection" conten ...

  3. python3绘图示例4(基于matplotlib:箱线图、散点图等)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from matplotlib.pyplot import * x=[1,2,3,4]y=[5,4,3,2] # ...

  4. 前端怎样学习react

    这是一个很长的话题.....慢慢写

  5. 第二章 LCD液晶显示屏&声控装置&播放音乐&遥控器

    这节我将带大家了解亮宁机器人编程的基础部分. LCD液晶显示屏 LCD液晶显示屏是在实现某种功能和调试中不可缺少的部分,接下来我带大家学习,如何使用LCD液晶显示屏. 首先我们把LCD液晶显示屏插入主 ...

  6. STM32-开发环境搭建-STM32CubeMX-安装及配置

    STM32CubeMX系列教程之1.流水灯 刚刚接触到STM32CubeMX软件,感觉挺有意思,动动鼠标使STM32开发变得简单,特写文与大家分享.但具体性能如何还需测试. 硬件开发中的流水灯相当于软 ...

  7. httpclient开启代理,获取java中请求的url

    背景:在httpclent做post或者get请求时,请求返回的数据总是和预想的不一致,但是有不知道怎么排查问题,经同事说httpclient可以设置代理,就可以获取请求前数据的一些问题,帮助我排查问 ...

  8. LCT入门

    前言 \(LCT\),真的是一个无比神奇的数据结构. 它可以动态维护链信息.连通性.边权.子树信息等各种神奇的东西. 而且,它其实并不难理解. 就算理解不了,它简短的代码也很好背. \(LCT\)与实 ...

  9. 抽象类和final

    抽象类: 概念:在继承过程中,形成一个继承金字塔,位于金字塔底部的类越来越具体(强大),位于塔顶的越来越抽象(简单). 关键字  :abstract 抽象类特性: [1]抽象类过于抽象,实例化后无语义 ...

  10. 【转】Android tools:context

    tools:context="com.example.guolin.scrollertest.MainActivity" 有时候可以看到有这个东西,但是从来没有用过,不知道有什么作 ...