# Apache ORC

**Apache ORC**（Optimized Row Columnar，优化行列式）是一种自描述、类型感知的列式文件格式，专为 Hadoop 工作负载设计，于 2013 年 1 月作为加速 [Apache Hive](https://www.edgepedia.org/zh/apache-hive)、提升 [Apache Hadoop](https://www.edgepedia.org/zh/apache-hadoop) 中数据存储效率的一项计划的一部分而创建。它针对大规模流式读取进行了优化，同时支持快速定位所需行，由 Apache 软件基金会作为顶级项目管理，提供 Java 和 C++ 两种实现。<sup>[1](https://orc.apache.org/docs/index.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 创建时间 | 2013 年 1 月，在 Apache Hive 内部创建；在 Hive 0.11.0 中以优化行列式格式引入<sup>[1](https://orc.apache.org/docs/index.html)</sup><sup> • </sup><sup>[2](https://hive.apache.org/docs/latest/language/languagemanual-orc/)</sup> |
| Apache 项目 | 2015 年 4 月 22 日经 ASF 董事会批准成立；2026 年 4 月报告有 49 名提交者和 16 名 PMC 成员<sup>[3](https://apache.org/foundation/board/minutes/ORC.html)</sup> |
| 文件组织 | 数据划分为条带，条带是分布式工作的自然单位；Hive 中默认条带大小为 250 MB，`orc.stripe.size` 默认为 67,108,864 字节<sup>[1](https://orc.apache.org/docs/index.html)</sup><sup> • </sup><sup>[2](https://hive.apache.org/docs/latest/language/languagemanual-orc/)</sup> |
| 索引 | 三级索引（文件、条带、行），行组默认每 10,000 行一组；自 Hive 1.2 起支持布隆过滤器<sup>[4](https://orc.apache.org/docs/indexes.html)</sup> |
| 压缩 | 类型特定的轻量级编码（游程编码、字典编码、增量编码、位打包）加上通用编解码器；默认 ZLIB，也支持 SNAPPY 和 NONE<sup>[5](https://orc.apache.org/specification/ORCv0/)</sup><sup> • </sup><sup>[2](https://hive.apache.org/docs/latest/language/languagemanual-orc/)</sup> |
| 实现 | 独立的 Java 和 C++ 读写库，各自都能读取所有版本的 ORC 文件<sup>[6](https://github.com/apache/orc)</sup> |
| 最新版本 | 2.3.1，2026 年 7 月 16 日发布，新增 Java 25 支持以及基于 lz4-java 的新 Lz4Codec<sup>[7](https://orc.apache.org/releases/)</sup> |

## 起源与项目历史

ORC 取代了 Hive 的 RCFile，后者曾是 Hadoop 中存储表格数据的标准格式，但将每一列视为没有语义的二进制块。在 Hive 0.11 中，开发者增加了优化行列式格式，它保留表定义中的类型信息，并使用类型特定的读写器。<sup>[5](https://orc.apache.org/specification/ORCv0/)</sup> 其既定目标是高速处理和减小文件体积。<sup>[1](https://orc.apache.org/docs/index.html)</sup>

Apache 软件基金会董事会于 2015 年 4 月 22 日批准成立 Apache ORC 项目。2026 年 4 月的董事会报告列出 49 名提交者和 16 名 PMC 成员，并提到 2.3.0 版本的发布，该版本带来了对 LTS Java 25 的支持。<sup>[3](https://apache.org/foundation/board/minutes/ORC.html)</sup>

## 文件结构

一个 ORC 文件包含称为条带的行数据组，以及一个文件尾部，并在文件末尾有一个附注，其中保存压缩参数和压缩后文件尾部的大小。文件尾部列出各条带、每条带的行数、每一列的数据类型，以及列级聚合值：计数、最小值、最大值和总和。<sup>[2](https://hive.apache.org/docs/latest/language/languagemanual-orc/)</sup>

每个条带都是自包含的，只需其自身的字节加上文件的尾部和附注即可读取，且每个条带只包含完整的行，因此行永远不会跨越条带边界。每个条带分为三部分：覆盖该条带各行的索引、数据本身，以及该条带的尾部。索引和数据部分都按列划分，因此读取器只读取所需列的数据；读取量与所读列数成正比。<sup>[5](https://orc.apache.org/specification/ORCv0/)</sup> 文件中的条带彼此独立，构成分布式工作的自然单位。<sup>[1](https://orc.apache.org/docs/index.html)</sup>

在条带内，每一列存储在几个流中，这些流在文件中彼此相邻放置。整数列使用一个 PRESENT 流（每个值一位，记录非空状态）和一个 DATA 流（存放非空值）；当条带中所有值均非空时，省略 PRESENT 流。二进制数据使用三个流：PRESENT、DATA 和 LENGTH。<sup>[5](https://orc.apache.org/specification/ORCv0/)</sup>

## 索引与谓词下推

ORC 在每个文件中提供三级索引：整个文件每一列的文件级统计信息、每个条带的条带级统计信息，以及条带内每 10,000 行一组的行级统计信息。文件和条带统计信息位于文件尾部中，因此读取器可以决定是否需要读取文件的其余部分。列统计信息始终包含值的计数以及是否存在空值；大多数原始类型还包括最小值和最大值，数值类型还包括总和。<sup>[4](https://orc.apache.org/docs/indexes.html)</sup>

读取器通过搜索参数（Search ARGuments，SARG）使用这些索引，SARG 是限制感兴趣行的简化表达式；对于查找年龄超过 100 岁的人的查询，只会读取包含此类人员的文件、条带或行组。自 Hive 1.2 起，索引可以包含布隆过滤器，从而提供更具选择性的过滤。<sup>[4](https://orc.apache.org/docs/indexes.html)</sup> 在 Hive 配置中，布隆过滤器通过 `orc.bloom.filter.columns` 按列启用，默认误报概率为 0.05。<sup>[2](https://hive.apache.org/docs/latest/language/languagemanual-orc/)</sup>

## 类型与自描述

作为一种自包含格式，ORC 文件既不需要 [Hive 元数据存储](https://www.edgepedia.org/zh/hive-metastore)，也不需要任何其他外部元数据，因为每个文件都携带理解其内容所需的全部类型和编码细节。类型系统涵盖整数（boolean、tinyint、smallint、int、bigint）、浮点数（float、double）、字符串（string、char、varchar）、二进制、十进制、日期与时间（timestamp、带本地时区的 timestamp、date），以及复合类型 struct、list、map 和 union。所有类型都可以取空值，包括复合类型。<sup>[8](https://orc.apache.org/docs/types.html)</sup> 元数据使用 [Protocol Buffers](https://www.edgepedia.org/zh/protocol-buffers) 存储，允许添加和删除字段。<sup>[2](https://hive.apache.org/docs/latest/language/languagemanual-orc/)</sup>

## 压缩与编码

写入器为每一列的类型选择适当的编码：整数列使用游程编码，字符串列使用字典编码，并采用位打包和[增量编码](https://www.edgepedia.org/zh/delta-encoding)等轻量级技术，再叠加通用压缩（zlib 或 Snappy）以进一步减小文件体积。<sup>[5](https://orc.apache.org/specification/ORCv0/)</sup> Hive 默认使用 ZLIB 压缩，块大小为 262,144 字节。<sup>[2](https://hive.apache.org/docs/latest/language/languagemanual-orc/)</sup> Spark 的文档强调 ORC 的特性包括原生 Zstandard 压缩、布隆过滤器和列式加密。<sup>[9](https://spark.apache.org/docs/4.0.0/sql-data-sources-orc.html)</sup> 近期版本扩展了编解码器支持：ORC 2.3 增加了基于 lz4-java 的新 Lz4Codec 和 XerialSnappyCodec。<sup>[7](https://orc.apache.org/releases/)</sup>

## 采用情况与其他格式的比较

大型 Hadoop 用户很早就采用了 ORC：Facebook 用它在其数据仓库中存储了数十 PB 的数据，并证明 ORC 显著快于 RC File 或 Parquet，Yahoo 则将其生产数据存储在 ORC 中。<sup>[1](https://orc.apache.org/docs/index.html)</sup> 引擎支持包括 [Apache Spark](https://www.edgepedia.org/zh/apache-spark)（同时提供 `native` 和 `hive` 两种 ORC 实现，且自 Spark 2.3 起默认使用向量化 ORC 读取器），以及 Trino 和 [Apache Gobblin](https://www.edgepedia.org/zh/apache-gobblin)。<sup>[9](https://spark.apache.org/docs/4.0.0/sql-data-sources-orc.html)</sup><sup> • </sup><sup>[10](https://orc.apache.org/docs/adopters.html)</sup>

比较研究表明存在权衡取舍，而非一边倒的赢家。[微软研究院](https://www.edgepedia.org/zh/microsoft-research)对 [Apache Arrow](https://www.edgepedia.org/zh/apache-arrow)、Parquet 和 ORC 在分析型 DBMS 中的评估发现，每种格式都有影响其在 DBMS 内适用性的权衡。<sup>[11](https://www.microsoft.com/en-us/research/publication/a-deep-dive-into-common-open-formats-for-analytical-dbmss/)</sup> 一篇学位论文的比较得出结论：ORC 在大规模流式读取和模式演进方面具有优势，而 Parquet 在效率和复杂数据结构方面表现更好。<sup>[12](https://www.doria.fi/bitstream/handle/10024/187408/hellman_fredrik.pdf?sequence=2)</sup> PHUSE 对临床报告格式的评估引用了在线基准测试，表明 ORC 在 I/O 效率和文件体积缩减方面通常略优于 Parquet。<sup>[13](https://phuse.s3.eu-central-1.amazonaws.com/Archive/2025/Connect/EU/Hamburg/PAP_TT11.pdf)</sup> 一项基准研究发现，Hive 使用 ORC 时表现优于 Parquet，而 Spark 则更青睐 Parquet。<sup>[14](https://pmc.ncbi.nlm.nih.gov/articles/PMC5504537/)</sup>

## 版本发布

项目维护并行的发布线；2.x 系列始于 2024 年 3 月的 2.0.0。当前版本 2.3.1（2026 年 7 月 16 日）包含 Java 和 C++ 读写器，以及用于检查 ORC 文件及其元数据的工具。2.3 的显著特性包括 Java 25 支持、新的 Lz4Codec、XerialSnappyCodec 支持、针对大输入行的条带刷新，以及 C++ 方面的改进，如对下一个条带的异步 I/O 预取。<sup>[7](https://orc.apache.org/releases/)</sup> 2.2.0 版本在 Java 和 C++ 中都增加了 Geometry 和 Geography 类型。<sup>[15](https://github.com/apache/orc/releases)</sup> 构建该项目需要 Java 17 或更高版本、Maven 3.9.9 或更高版本，以及 CMake 3.25.0 或更高版本。<sup>[6](https://github.com/apache/orc)</sup>

## References

1. [Background, Apache ORC documentation](https://orc.apache.org/docs/index.html)
2. [Apache Hive: LanguageManual ORC](https://hive.apache.org/docs/latest/language/languagemanual-orc/)
3. [Board history: ORC, Apache Software Foundation](https://apache.org/foundation/board/minutes/ORC.html)
4. [Indexes, Apache ORC documentation](https://orc.apache.org/docs/indexes.html)
5. [ORC Specification v0](https://orc.apache.org/specification/ORCv0/)
6. [GitHub: apache/orc](https://github.com/apache/orc)
7. [Releases, Apache ORC](https://orc.apache.org/releases/)
8. [Types, Apache ORC documentation](https://orc.apache.org/docs/types.html)
9. [ORC Files, Spark 4.0.0 Documentation](https://spark.apache.org/docs/4.0.0/sql-data-sources-orc.html)
10. [ORC Adopters, Apache ORC documentation](https://orc.apache.org/docs/adopters.html)
11. [A Deep Dive into Common Open Formats for Analytical DBMSs, Microsoft Research](https://www.microsoft.com/en-us/research/publication/a-deep-dive-into-common-open-formats-for-analytical-dbmss/)
12. [Fredrik Hellman, comparison of ORC and Parquet, University of Helsinki (Doria)](https://www.doria.fi/bitstream/handle/10024/187408/hellman_fredrik.pdf?sequence=2)
13. [An Evaluation of Data Formats for Clinical Reporting in a Multilingual Environment, PHUSE Connect EU 2025](https://phuse.s3.eu-central-1.amazonaws.com/Archive/2025/Connect/EU/Hamburg/PAP_TT11.pdf)
14. [Benchmarking distributed data warehouse solutions for storing genomic variant information, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC5504537/)
15. [Releases, apache/orc on GitHub](https://github.com/apache/orc/releases)

---
*Initially written Oct 26, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Databases and data systems › Data mining, warehousing, and big data › Big data platforms and frameworks

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/apache-orc

English original: https://www.edgepedia.org/apache-orc
