Hive优化——ORCFile简介

Hive优化——ORCFile简介

一、ORC文件格式简介

The Optimized Row Columnar (ORC) file format provides a highly efficient way to store Hive data. It was designed to overcome limitations of the other Hive file formats. Using ORC files improves performance when Hive is reading, writing, and processing data.
优化的行列(ORC)文件格式提供了一种高效的存储Hive数据的方法。它旨在克服其他Hive文件格式的限制。当Hive正在读取、写入和处理数据时,使用ORC文件可以提高性能。
Compared with RCFile format, for example, ORC file format has many advantages such as:

  • a single file as the output of each task, which reduces the NameNode’s load
  • 一个task产生一个文件,减少了NameNode的负载
  • Hive type support including datetime, decimal, and the complex types (struct, list, map, and union)
  • 支持datetime,decimal以及多种复杂类型
  • light-weight indexes stored within the file
  • 文件中存储轻量级索引
    • skip row groups that don’t pass predicate filtering
    • 跳过不通过谓词筛选的行组
    • seek to a given row
    • 寻找给定的行
  • block-mode compression based on data type
  • 基于数据类型的块模式压缩
    • run-length encoding for integer columns
    • 整数列的行程编码
    • dictionary encoding for string columns
    • 字符串列的字典编码
  • concurrent reads of the same file using separate RecordReaders
  • 使用单独的 RecordReaders 并发读取同一个文件
  • ability to split files without scanning for markers
  • 能够在不扫描标记的情况下拆分文件
  • bound the amount of memory needed for reading or writing
  • 限制了读或写所需的内存量
  • metadata stored using Protocol Buffers, which allows addition and removal of fields
  • 使用Protocol Buffers存储的元数据,允许添加和删除字段

二、ORCFile 文件结构

An ORC file contains groups of row data called stripes, along with auxiliary information in a file footer. At the end of the file a postscript holds compression parameters and the size of the compressed footer.

ORC文件包含称为条带的行数据组以及文件页脚中的辅助信息。在文件的末尾,postscript保存压缩参数和压缩页脚的大小。

The default stripe size is 250 MB. Large stripe sizes enable large, efficient reads from HDFS.

Strip 默认的大小是250MB,大Strip大小可实现HDFS的大量高效读取

The file footer contains a list of stripes in the file, the number of rows per stripe, and each column’s data type. It also contains column-level aggregates count, min, max, and sum.

文末尾包含一个文件中Stripes的列表,包含每个 stripe 的行数,每列的数据类型。它同时包含列聚合计数、最小值、最大值、和。

This diagram illustrates the ORC file structure:

ORC文件结构:

orc文件结构

文件结构 【参考:ORC文件格式
  和Parquet类似,ORC文件也是以二进制方式存储的,所以是不可以直接读取,ORC文件也是自解析的,它包含许多的元数据,这些元数据都是同构ProtoBuffer进行序列化的。ORC的文件结构如下图,其中涉及到如下的概念:

ORC文件:保存在文件系统上的普通二进制文件,一个ORC文件中可以包含多个stripe,每一个stripe包含多条记录,这些记录按照列进行独立存储,对应到Parquet中的row group的概念。
文件级元数据:包括文件的描述信息PostScript、文件meta信息(包括整个文件的统计信息)、所有stripe的信息和文件schema信息。
stripe:一组行形成一个stripe,每次读取文件是以行组为单位的,一般为HDFS的块大小,保存了每一列的索引和数据。
stripe元数据:保存stripe的位置、每一个列的在该stripe的统计信息以及所有的stream类型和位置。
row group:索引的最小单位,一个stripe中包含多个row group,默认为10000个值组成。
stream:一个stream表示文件中一段有效的数据,包括索引和数据两类。索引stream保存每一个row group的位置和统计信息,数据stream包括多种类型的数据,具体需要哪几种是由该列类型和编码方式决定。
在ORC文件中保存了三个层级的统计信息,分别为文件级别、stripe级别和row group级别的,他们都可以用来根据Search ARGuments(谓词下推条件)判断是否可以跳过某些数据,在统计信息中都包含成员数和是否有null值,并且对于不同类型的数据设置一些特定的统计信息。
(1)file level
  在ORC文件的末尾会记录文件级别的统计信息,会记录整个文件中columns的统计信息。这些信息主要用于查询的优化,也可以为一些简单的聚合查询比如max, min, sum输出结果。
(2)stripe level
  ORC文件会保存每个字段stripe级别的统计信息,ORC reader使用这些统计信息来确定对于一个查询语句来说,需要读入哪些stripe中的记录。比如说某个stripe的字段max(a)=10,min(a)=3,那么当where条件为a >10或者a <3时,那么这个stripe中的所有记录在查询语句执行时不会被读入。
(3)row level
  为了进一步的避免读入不必要的数据,在逻辑上将一个column的index以一个给定的值(默认为10000,可由参数配置)分割为多个index组。以10000条记录为一个组,对数据进行统计。Hive查询引擎会将where条件中的约束传递给ORC reader,这些reader根据组级别的统计信息,过滤掉不必要的数据。如果该值设置的太小,就会保存更多的统计信息,用户需要根据自己数据的特点权衡一个合理的值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值