Repository navigation
Replace the apache/orc library with a native ORC reader and writer - #127690
Conversation
The ORC reader and writer are implemented in `src/Processors/Formats/Impl/ORC`, similarly to the native Parquet and Arrow IPC implementations. They follow the semantics of the C++ ORC library that was used before, so the existing behavior is kept: the same type mapping (the conversion code is unchanged), the same column selection, the same predicate pushdown (search arguments with the same normalization, file, stripe and row group statistics, bloom filters), the same time zone handling of `TIMESTAMP`, and the same file layout and statistics on write (the files are read identically by the old reader, and the old files by the new one). The metadata is parsed and serialized with a small hand-written Protocol Buffers implementation, so the build does not run `protoc` for ORC anymore. All codecs are supported for reading (including LZO) and all codecs except LZO and BROTLI for writing, as before. The `contrib/orc` submodule is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflict on `contrib/orc` in favor of its deletion. The new test `05407_orc_timezone_traversal_abort` checked the error message of the ORC library; the native reader resolves the time zones only from the embedded time zone database, so it now checks that such a time zone is rejected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [f0e7321] Summary: ✅
AI ReviewSummaryThe PR replaces Apache ORC with native ClickHouse reading and writing. Review of Missing context / blind spots
Final Verdict✅ Approve — no unresolved review findings. |
The reader decodes the values of the primitive types directly into the ClickHouse columns of their natural types (`Int8`, `Int16`, `Int32`, `Int64`, `Float32`, `Float64`, `Bool`, `String`), the lengths of lists and maps into the offsets of `ColumnArray`, and the string dictionaries into `ColumnString`, which is used as is for `LowCardinality`. The conversion to the requested types takes these columns without copying. `DATE`, `TIMESTAMP` and `DECIMAL` keep their intermediate values, which are needed to check the ranges and the scales. The writer encodes the values directly from the ClickHouse columns, with the same conversions as before (the unsigned integers as the signed ones of the same width, `DateTime64` as seconds and nanoseconds, `FixedString`, `IPv6` and the big integers as their raw bytes, `Variant` as UNION), instead of copying them into the intermediate batches first. The output is byte-identical. On 20 million rows of mixed types, reading is 1.2 to 2 times faster than with the intermediate batches (depending on the columns), and writing is 10% faster, with less memory in both cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Date` is the unsigned number of days, but it was written to ORC as a signed 16-bit number, as the unsigned integer types are, so the dates after 2059-09-18 (more than 32767 days) were written as negative numbers of days and read back as the dates before 1970: for example, 2100-01-01 as 1920-07-28. The statistics were wrong in the same way, so the filter pushdown could skip the matching rows. The C++ ORC library had the same behavior. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… test `no-fasttest` ORC is not built in the fast test, so `05447_orc_native_reader_writer` failed with `Unknown format ORC`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127690&sha=latest&name_0=PR&name_1=Build%20(arm_tidy%2C%204%2F4) #127690 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/Writer.cpp.o |
new | 338.84 KiB | +338.84 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/Reader.cpp.o |
new | 271.04 KiB | +271.04 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/ColumnReader.cpp.o |
new | 260.90 KiB | +260.90 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/SearchArgument.cpp.o |
new | 184.77 KiB | +184.77 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/Proto.cpp.o |
new | 181.77 KiB | +181.77 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/Type.cpp.o |
new | 108.12 KiB | +108.12 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/RLE.cpp.o |
new | 90.38 KiB | +90.38 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/Vector.cpp.o |
new | 82.11 KiB | +82.11 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/Stream.cpp.o |
new | 81.08 KiB | +81.08 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/Compression.cpp.o |
new | 75.83 KiB | +75.83 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/Statistics.cpp.o |
new | 44.59 KiB | +44.59 KiB |
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORCBlockOutputFormat.cpp.o |
256.33 KiB | 230.43 KiB | -25.90 KiB (-10.10%) |
src/Storages/System/CMakeFiles/clickhouse_storages_system.dir/StorageSystemLicenses.generated.cpp.o |
2.10 MiB | 2.09 MiB | -16.87 KiB (-0.78%) |
766 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
24 translation units recompiled, 86 s compile time in total, 13 of them have a recent master baseline.
Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +4.6 s (+8%) in total before that adjustment.
…nts, allow nested dictionaries Remove the bound of a string dictionary by the number of rows of the stripe, because a column nested in a list or a map can have more values. Validate the precision and the scale of the decimal type and the per-value scales from the file, so the differences of the scales cannot overflow. Reject bloom filters with more than 256 hash functions. Fix the tests: `05447_orc_native_reader_writer` printed timestamps in the random session time zone, and `04337_orc_schema_inference_deep_recursion` failed under TSan where the stack size check fires before the depth limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… ORC statistics conservative `Reader::preBuffer` scheduled the asynchronous read before the cache owned the buffer, so an exception from `cache.push_back` could free the buffer while the background read was still writing into it. Insert the entry into the cache first, and remove it only if scheduling the read fails. In `HiveORCFile::buildRange`, a missing `has_null` now means that the column may contain nulls, and the deprecated local-time timestamp bounds are no longer used for the file index, because the writer time zone is unknown at the file level. This matches the behavior of the replaced library. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged master and addressed the three review threads in 4c88afb. The new tests The remaining CI failures are performance regressions in the native reader. They are caused by this PR and are not fixed yet:
Locally, subfield pruning does work: |
…th incorrect hashing The C++ writer of ORC 1.6.0 - 1.6.11 and 1.7.0 hashed the integers incorrectly (ORC-1024), and liborc did not use such bloom filters (`hasBadBloomFilters`). The native reader used them, so the equality and `IN` pushdown could skip row groups with matching rows. Restore the same exclusion by the writer id and `software_version`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The files `bad_bloom_filter_1.6.0.orc` and `bad_bloom_filter_1.6.11.orc` are from https://github.com/apache/orc/tree/main/examples. Without ignoring their bloom filters, `id = 18000000000` and `id IN (...)` return no rows with `input_format_orc_filter_push_down`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`IntRleDecoderV2::readInts` read every byte with `readByte`, which checks the end of the chunk each time. It took 60% of the time of reading wide integer columns, so the native reader was slower than liborc in `orc_tuple_field_prune` (up to 2x locally). Decode the values that are in the current chunk without the checks, with the byte width known at compile time. Locally: `orc_tuple_field_prune` queries 26 -> 11 ms, 40 -> 39 ms, 83 -> 44 ms (liborc: 12, 47, 70 ms). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127690&sha=4c88afbedf85e1d51a153ceed0845f338d34463f&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%207%2F8%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The server of The performance regressions in |
|
The fix is already in progress: ClickHouse/librdkafka#24 (base
|
ORC is not built in the fast test, so the format cannot be detected there. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127690&sha=15ebe49431f69daa26c434c5e9344d437e257aed&name_0=PR&name_1=Fast%20test #127690 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #127690 to 26.3: Replace the apache/orc library with a native ORC reader and writer
…e ORC reader and writer
Backport #127690 to 26.10: Replace the apache/orc library with a native ORC reader and writer
Backport #127690 to 26.8: Replace the apache/orc library with a native ORC reader and writer
Backport #127690 to 26.9: Replace the apache/orc library with a native ORC reader and writer
Backport #127690 to 26.3: Replace the apache/orc library with a native ORC reader and writer
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/1344 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/1384 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
The ORC format no longer uses the
apache/orcC++ library. The reader and the writer are implemented insrc/Processors/Formats/Impl/ORC, similarly to the native Parquet and Arrow IPC implementations, and thecontrib/orcsubmodule is removed.What liborc was used for
NativeORCBlockInputFormat: file tail and stripe parsing, all column encodings (RLE v1/v2, byte/boolean RLE, direct and dictionary strings, decimals, timestamps, nested types and unions), lazy dictionary decoding forLowCardinality, stripe prefetching, the writer/reader time zone adjustment ofTIMESTAMP, and predicate pushdown by file, stripe and row group statistics and bloom filters.ORCBlockOutputFormat: the encodings, the row index, the statistics, five codecs, and the type attributes for the Iceberg field ids.HiveFile: the file and stripe statistics for the min/max indexes.Approach
The new code follows the semantics of liborc, so the behavior is kept:
Int8...Int64,Float32,Float64,Bool,String), the lengths of lists and maps directly into the offsets ofColumnArray, and the string dictionaries intoColumnString, which is used as is forLowCardinality. The type conversion code inNativeORCBlockInputFormat.cpp(type hints, unions, overflow checks) is kept and takes these columns without copying.DATE,TIMESTAMPandDECIMALkeep intermediate values, which are needed for the range and scale checks.DateTime64as seconds and nanoseconds,FixedString,IPv6and big integers as raw bytes,Variantas UNION).rows_readwith filter pushdown is the same.protocfor ORC anymore.Codecs: none, zlib, snappy, LZ4, zstd for reading and writing; LZO for reading only (as before). BROTLI is rejected with
NOT_IMPLEMENTED, as before.Compatibility checks
IPv4,IPv6,Int128,FixedString,DateTime, nullable tuples with nullable fields,Variant,LowCardinality(Nullable), nested arrays).Performance
20M rows of mixed types, zstd, best of 5 (on a loaded machine, so the ratios matter more than the absolute numbers):
Peak memory is somewhat higher than with liborc (about 50 MB for reading, because the selected columns of a stripe are loaded at once; about 15% for writing, because the strings of a stripe are buffered). The files are 0.3% larger with zstd; with LZ4 they are half the size, because liborc used the maximum LZ4 acceleration.
Bug fix
Datevalues after 2059-09-18 were written as negative numbers of days (as the signed 16-bit numbers that the unsigned integers are written as), so they read back as dates before 1970, e.g. 2100-01-01 as 1920-07-28, and their statistics were wrong as well. liborc had the same behavior. They are now written correctly (test05448_orc_date_after_2059).Test changes
01308_orc_output_format_arraysand02426_orc_bugcompare MD5 of the output bytes. They differ only in the metadata: the software version and the collection statistics, which liborc filled only when a batch had nulls and are now always correct.04856,05036,05317matched liborc's error messages or exception class names and now match the new messages.05447_orc_native_reader_writer._orctarget; it now requires snappy and Parquet.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
ORCformat is now read and written by a native implementation instead of the Apache ORC C++ library, with the same behavior and the same files on output. The values are read and written directly into and from ClickHouse columns: reading is 1.4 to 2.3 times faster and writing is about 25% faster. The build does not needprotocfor ORC anymore. Fixed writingDatevalues after 2059-09-18 to ORC, which were read back as dates before 1970.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127690]
Version info
26.11.1.1012-master(included in26.11and later)