Skip to content

feat(ipc): support writing LZ4 and ZSTD compressed IPC streams and files - #935

Merged
paleolimbot merged 14 commits into
apache:mainfrom
pdet:ipc-write-compression
Sep 9, 2026
Merged

feat(ipc): support writing LZ4 and ZSTD compressed IPC streams and files#935
paleolimbot merged 14 commits into
apache:mainfrom
pdet:ipc-write-compression

Conversation

@pdet

@pdet pdet commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This PR adds LZ4 and ZSTD compression to nanoarrow’s IPC encoder and writer, allowing applications to write compressed Arrow streams and files. The motivation comes from the duckdb-arrow extension, where we want nanoarrow to handle compression while the extension takes care of the SQL options. To support this, callers can select a codec and compression level, query the supported level range, and convert between codec names and enum values without needing to include the compression libraries’ headers themselves.

Compression happens per buffer within each record batch, following the Arrow IPC format. If compressing a buffer does not make it smaller, we store it uncompressed, and empty buffers remain empty. The implementation provides a serial compressor by default, with an interface for applications to supply their own. Unsupported codecs and out-of-range levels are rejected when configuring the built-in compressor, so callers can report these errors before writing data. The added tests cover compression and decompression roundtrips, compressed streams and files, compression levels, and builds with either codec unavailable.

@codecov-commenter

codecov-commenter commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.99320% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.49%. Comparing base (9dd6c4b) to head (fd1023e).

Files with missing lines Patch % Lines
src/nanoarrow/ipc/encoder.c 78.80% 8 Missing and 24 partials ⚠️
src/nanoarrow/ipc/codecs.c 90.35% 7 Missing and 4 partials ⚠️
src/nanoarrow/ipc/decoder.c 63.15% 3 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #935      +/-   ##
==========================================
+ Coverage   79.29%   79.49%   +0.20%     
==========================================
  Files         106      106              
  Lines       16316    16564     +248     
  Branches     1925     1986      +61     
==========================================
+ Hits        12937    13167     +230     
- Misses       2163     2164       +1     
- Partials     1216     1233      +17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

A few conceptual questions (feel free to push back of they don't make sense!)...I'll follow up with a review focused on correctness with the help of the robots after

This needs a rebase or a merge from main (sorry!) from the initial work on Dictionary writes.

Comment thread src/nanoarrow/ipc/codecs.c Outdated
Comment thread src/nanoarrow/ipc/encoder.c Outdated
Comment thread src/nanoarrow/ipc/encoder.c Outdated
Comment thread src/nanoarrow/ipc/encoder.c
Comment thread src/nanoarrow/nanoarrow_ipc.h Outdated
Comment thread src/nanoarrow/nanoarrow_ipc.h Outdated
@pdet

pdet commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @paleolimbot! Merged with the latest main and walked through your points.

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Codex turned up an unrelated issue surfaced here we can tackle separately ( #936 ).

Comment on lines +864 to +867
// don't leave queued work referring to our buffers behind
struct ArrowError ignored;
NANOARROW_UNUSED(
private->compressor.compress_wait(&private->compressor, -1, &ignored));

@paleolimbot paleolimbot Sep 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit: You should be able to pass NULL for the error here.

@paleolimbot
paleolimbot merged commit 6657945 into apache:main Sep 9, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants