Parquet与ORC对比

Parquet

http://parquet.apache.org

Orc

http://orc.apache.org

发展状态

目前都是Apache开源的顶级项目,列式存储引擎

开发语言

Java

主导公司

Twitter/Cloudera

Hortonworks

列编码

支持多种编码,字典,RLE,Delta等

支持主流编码,与Parquet类似

                    ACID

不支持

支持ACID事务

修改操作(update,delete)

不支持

支持

支持索引

(统计信息)

粗粒度索引

block/group/chunk级别统计信息

粗粒度索引

file/stripe/row级别统计信息,不能精确到列建立索引

查询性能

Orc性能更高一点

压缩比

Orc压缩比更高

下面看一张图,可以比对一下压缩率:

4、ORC

使用ORC文件格式可以提升Hive读、写与处理数据的性能。

一个ORC文件包含多个stripes(每个stripes由多组行数据组成的),一个包含辅助信息的file footer。

在文件的结尾,一个postscript保存着压缩参数及被压缩的footer的长度。

一个stripes缺省大小是250MB,其大小可以扩展的长度只受HDFS的约束。

file footer包含文件中的一个记录stripes信息的列表、每个stripes中行的数目及每个列的数据类型,它也包含列级的聚合结果:count, min, max, and sum。

我们通过使用hive --orcfiledump来进行分析ORC存储文件,就可以看到这些信息:

hive --orcfiledump <path_to_file>

示例:

hive --orcfiledump /user/hive/warehouse/helloworld.db/test_orcfile/part-00271

对于Hive 1.1,查看ORC File文件中的内容可以使用如下的方式:

hive --orcfiledump -d <path_to_file>

示例:

hive --orcfiledump -d /user/hive/warehouse/helloworld.db/test_orcfile/part-00271

从下面的ORC文件结构图可以了解相关信息:

我使用下面的命令,将ORC的分析结果输出到了orcfile文件,方便大家查看对照图分析:

hive --orcfiledump /user/hive/warehouse/helloworld.db/test_orcfile/part-00271 > orcfile

从上图中,我们知道在ORC文件中,每个Stripe包括索引数据(IndexData)、行数据(Row Data)及一个Stripe footer。

Stripe footer包含了用于流定位的目录,Row data用于表扫描。

索引数据(Index Data)包括每个列的最小与最大值,以及它们在每个列的行号,行索引项(Row index entries)记录了压缩块及解压后字节的偏移。需要注意的是,ORC索引只是被用来选择Stripe和行组,而不会被用于返回查询结果。拥有相对频繁的行索引条目,可以为了快速的数据读取而跳过一些行,缺省情况下每次最多可以跳过10000行。ORC有能力基于过滤谓词跳过非常多的行,可以使用第二关键字进行对表进行排序,以达到减少查询执行时间的效果。例如,如果主关键字是交易日期,表可以按照省份、邮编号码或者姓名进行排序,当按照省份查询记录的时候将跳过非目标省份的记录。

下面介绍如何在Hive中使用这种存储格式:

1) 支持的数据格式

Integer
    boolean (1 bit)
    tinyint (8 bit)
    smallint (16 bit)
    int (32 bit)
    bigint (64 bit) 
Floating point

    float
    double 
String types
    string
    char
    varchar 
Binary blobs
    binary 
Date/time
    timestamp
    date 
Compound types
    struct
    list
    map
    union 

2) Hive DDL

通过指定stored as orc来使用ORC存储格式:

create table orc_table (

id int,

name string

) stored as orc;

可以修改表的存储格式:

alter table simple_table set fileformat orc;

如果simple_table已经存在数据,将导致通过表查询无法访问数据。

3) 创建表时,指定ORC存储格式属性

KEYDEFAULTNOTES
orc.compressZLIBhigh level compression = {NONE, ZLIB, SNAPPY}压缩方法(NONE, ZLIB, SNAPPY)
orc.compress.size262,144compression chunk size每个压缩块的字节数
orc.stripe.size268,435,456memory buffer size in bytes for writing每个stripe的字节数
orc.row.index.stride10,000number of rows between index entries索引项之间的行数
orc.create.indexTRUEcreate indexes?是否创建行索引
orc.bloom.filter.columns""comma separated list of column names
orc.bloom.filter.fpp0.05bloom filter false positive rate

比如,创建没有压缩的表:

CREATE TABLE orc_table (

name STRING,

age tinyint

) STORED AS ORC TBLPROPERTIES("orc.compress"="NONE");

4) Hive涉及ORC存储文件的配置参数

· hive.default.fileformat

指定Hive创建表的存储文件格式,默认为TextFile。

· hive.exec.orc.default.compress

ORC的压缩编码方式,默认为ZLIB。

· hive.exec.orc.default.buffer.size

ORC的缓冲大小,默认为262,144(256KB)。

· hive.exec.orc.default.block.size
ORC文件的系统块大小,默认为268,435,456(256MB)

· hive.exec.orc.zerocopy

使用zerocopy读ORC文件。Hadoop 2.3以及后续版本支持。

· hive.orc.compute.splits.num.threads

ORC使用多少线程去并行化创建分片

hive.exec.orc.skip.corrupt.data false

If ORC reader encounters corrupt data, this value will be used todetermine whether to skip the corrupt data or throw an exception.

The default behavioris to throw an exception.

· hive.exec.orc.skip.corrupt.data

如果ORC读时遇到损坏的数据,此选项决定是否跳过损坏的数据,还是抛出异常。

默认是抛出异常。

· hive.merge.orcfile.stripe.level

当hive.merge.mapfiles,hive.merge.mapredfiles或者hive.merge.tezfiles设置为true时,此时同时以ORC文件格式写表数据,设置此值为true时将快速以stripe级别合并ORC小文件。

· 其他的参数有的用的很少,大家可以参考Hive官网说明进行配置和调优