feat(writer): add ZLIB, Snappy, LZ4, and Zstd compression support - #86
Open
Allegre7tto wants to merge 4 commits into
Open
feat(writer): add ZLIB, Snappy, LZ4, and Zstd compression support#86Allegre7tto wants to merge 4 commits into
Allegre7tto wants to merge 4 commits into
Conversation
Collaborator
|
@codex review |
Author
|
It looks like the CI failure may be unrelated to my changes. Is there anything I need to do about it? |
Collaborator
fixed in #87 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(writer): add ZLIB, Snappy, LZ4, and Zstd compression support
Background
While working on Apache Auron, I found that the native Rust ORC writer is still missing several capabilities required by downstream projects. In particular, it currently writes uncompressed ORC files even though the reader already supports multiple compression codecs.
I would like to contribute to improving the writer, and writer-side compression seems like a useful and reasonably self-contained place to start.
Writer development is already tracked in #15, and there are two related open pull requests, #82 and #84, which have not received further updates since early May. This implementation also addresses several points raised around #82, including avoiding unnecessary allocations in the uncompressed path, reusing the existing compression infrastructure, adding LZ4 support, and validating interoperability with PyORC.
Proposed scope
This PR adds configurable writer-side compression for:
LZO remains unsupported for writing and produces an explicit error when selected.
The implementation follows ORC's block compression format:
Compression is applied independently to:
The PostScript remains uncompressed and records the selected compression kind and block size so that readers can decode the rest of the file correctly.
Compression is disabled by default, preserving the existing writer behavior.
Proposed API
Compression can be configured through
ArrowWriterBuilder:When no compression codec is configured, the writer continues to produce an uncompressed ORC file.
The default compression block size is 256 KiB when compression is enabled and no custom block size is provided.
Implementation
The work is organized into three commits.
1.
feat: add compressor infrastructure with four codec supportThis commit extends the existing compression module so that the reader and writer share the same compression types and codec dependencies.
It adds:
Compressor;Keeping compression and decompression in the same module avoids creating parallel codec abstractions and helps ensure that the generated block format matches what the reader already expects.
2.
feat: integrate ORC writer compressionThis commit integrates the compressor with
ArrowWriterBuilder,ArrowWriter, andStripeWriter.It adds builder configuration for the codec and block size, then applies compression to each independently encoded ORC stream. Stripe footer lengths, data lengths, and physical stripe offsets are calculated using the compressed byte lengths.
At file close, the implementation also compresses the metadata and file footer before writing an uncompressed PostScript containing:
CompressionKind;When compression is disabled,
Compressor::compressreturnsCow::Borrowedrather than allocating and copying the input. This preserves the existing direct-write behavior for uncompressed files and avoids introducing an allocation regression into the default code path.3.
test: verify compressed ORC writer compatibilityThis commit adds an external interoperability test using PyORC.
For each supported codec, the test:
The test is ignored by default because it requires a Python environment with PyORC installed.
Tests
The implementation includes tests covering the compression framing, writer integration, file metadata, physical offsets, and external interoperability.
Compression unit tests
Decompressor;Writer tests
CompressionKindvalidation;External interoperability test
Run the optional interoperability test with a Python environment containing
pyorc:cargo test --test writer_compression compressed_files_are_readable_by_pyorc \ -- --ignored --nocaptureChecklist
Tests
Validation
cargo buildcargo fmt -- --checktaplo formattyposcargo test --all-featurescargo test --no-default-featurescargo clippy --all-targets --all-features -- -D warningscargo clippy --all-targets --no-default-features -- -D warnings