Skip to content

GH-47752: [C++][Python][Parquet] Add minimum compression savings for V2 pages - #52580

Merged
rok merged 18 commits into
apache:mainfrom
MashrafeeAryan:adaptive-compression
Nov 2, 2026
Merged

rok merged 18 commits into
apache:mainfrom
MashrafeeAryan:adaptive-compression

Conversation

@MashrafeeAryan

@MashrafeeAryan MashrafeeAryan commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #47752.

Rationale for this change

Parquet's V2 pages currently keep compression whenever the compressed values are smaller than the original values. Even if it saves very little space, it still does it. For instance, it can compress 100 KB to 99 KB and save it. Even though that's 1% storage efficient, it might not be worth the decompression overhead while reading the file.

What changes are included in this PR?

In the PR, I added an optional min_compression_savings setting between 0.0 and 1.0. It gives users an option to select the minimum threshold to compress V2 page data values. For instance, if the original file is 100 KB and the user has min_compression_savings= 0.1, it means the compressed file needs to save at least 10% space. As a result, unless the file is <= 90 KB, it won't get saved.

I keep the current behavior when the user does not set min_space_savings.

Added C++ and Python implementation.

Are these changes tested?

  • C++ implementation has been tested with unit tests.
  • PyArrow implementation has been tested with unti tests.

Are there any user-facing changes?

C++ and Python users can set min_compression_savings when writing V2 pages. For example, 0.1 requires at least 10% space savings before keeping compression.

Was AI used for this PR?

ChatGPT helped to set up the build for PyArrow.

Codex helped find a bug in dataset_writing which ignored min_space_savings.

PR code and description written by:

  • Human (I wrote it. Used ChatGPT to fix my grammar.)
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #47752 has been automatically assigned in GitHub to PR creator.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #47752 has been automatically assigned in GitHub to PR creator.

1 similar comment
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #47752 has been automatically assigned in GitHub to PR creator.

@rok rok 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.

This looks great @MashrafeeAryan!
I left some inline comments, noting major.
Besides addressing the linter errors, we should update the Python docs. A new option is added to write_table, ParquetWriter, write_to_dataset and ParquetFileWriteOptions. We should update _parquet_writer_arg_docs in python/pyarrow/parquet/core.py and the data-page-V2 paragraph in docs/source/cpp/parquet.rst.

Comment thread cpp/src/parquet/properties.h Resolved
Comment thread cpp/src/parquet/properties.h Resolved
Comment thread cpp/src/parquet/column_writer.cc Resolved
Comment thread cpp/src/parquet/properties.h Resolved
Comment thread cpp/src/parquet/properties.h Resolved
@rok

rok commented Oct 23, 2026

Copy link
Copy Markdown
Member

Doc issue appears to be from wrong ordering in _parquet_writer_arg_docs. min_space_savings must com last before kwargs.

PR03: Wrong parameters order. Actual: ('table', 'where', 'row_group_size', 'version', 'use_dictionary', 'compression', 'write_statistics', 'use_deprecated_int96_timestamps', 'coerce_timestamps', 'allow_truncated_timestamps', 'data_page_size', 'flavor', 'filesystem', 'compression_level', 'use_byte_stream_split', 'column_encoding', 'data_page_version', 'use_compliant_nested_type', 'encryption_properties', 'write_batch_size', 'dictionary_pagesize_limit', 'store_schema', 'write_page_index', 'write_page_checksum', 'sorting_columns', 'store_decimal_as_integer', 'write_time_adjusted_to_utc', 'max_rows_per_page', 'bloom_filter_options', 'use_content_defined_chunking', 'min_space_savings', '**kwargs'). Documented: ('table', 'where', 'row_group_size', 'version', 'use_dictionary', 'compression', 'write_statistics', 'use_deprecated_int96_timestamps', 'coerce_timestamps', 'allow_truncated_timestamps', 'data_page_size', 'flavor', 'filesystem', 'compression_level', 'use_byte_stream_split', 'column_encoding', 'data_page_version', 'min_space_savings', 'use_compliant_nested_type', 'encryption_properties', 'write_batch_size', 'dictionary_pagesize_limit', 'store_schema', 'write_page_index', 'write_page_checksum', 'sorting_columns', 'store_decimal_as_integer', 'write_time_adjusted_to_utc', 'max_rows_per_page', 'bloom_filter_options', 'use_content_defined_chunking', '**kwargs')

@rok

rok commented Oct 23, 2026

Copy link
Copy Markdown
Member

@MashrafeeAryan this is looking good, some minor suggestions from me, but I think it's ready for another reviewer. Feel free to take it out of draft.

@pitrou could we ask you for a review here?

@rok

rok commented Oct 26, 2026

Copy link
Copy Markdown
Member

Ping @pitrou :)

@pitrou

pitrou commented Oct 26, 2026

Copy link
Copy Markdown
Member

I've submitted #55272 to write V2 data pages by default.

Comment thread cpp/src/parquet/properties.h Resolved
Comment thread cpp/src/parquet/properties.h Resolved
Comment thread python/pyarrow/tests/test_dataset.py Resolved
@rok

rok commented Oct 26, 2026

Copy link
Copy Markdown
Member

I've submitted #55272 to write V2 data pages by default.

@pitrou that's good. I don't think it changes anthing for this PR?

Also, please note @MashrafeeAryan is my intern and will work on fast read/write path for fixed size lists. (As proposed by hardwood).

@pitrou

pitrou commented Oct 26, 2026

Copy link
Copy Markdown
Member

@pitrou that's good. I don't think it changes anthing for this PR?

No.

@MashrafeeAryan

Copy link
Copy Markdown
Contributor Author

Hi @rok and @pitrou, I have addressed the comments. Please let me know if there is anything else needed! Thank you so much for taking the time to review the PR!

@rok

rok commented Nov 2, 2026

Copy link
Copy Markdown
Member

@MashrafeeAryan Can you fix the lint failure?

I think lint issue was fixed on main, so rebase should fix it.

MashrafeeAryan and others added 17 commits November 2, 2026 07:08
Add min_space_savings to control how much space compression must save. V2 pages below the threshold are written uncompressed. Keep the default behavior and V1 pages unchanged.
Add an option to choose how much space compression must save when writing Parquet files from Python.
Add tests as well.
Dataset writing ignored min_space_savings. Move the argument to the end of the call so it reaches the writer. Add a test to check that the setting changes the file size.
Throw an error when users set min_space_savings for V1 pages. Update C++ and Python tests.
Require compressed data to be smaller, even when min_space_savings is 0.0. Simplify the compression check and update the test.
Check min_space_savings when users set it. Update the test and Python error handling.
Check compressed and original sizes in the existing test. Keep checking that the data reads back correctly.
Explain min_space_savings in the Python and C++ docs.
Fix spacing and line wrapping in the C++ changes.
Allow zero with V1 and reject nonzero values. Combine dataset tests and keep threshold checks in C++. Update docs to match.
Co-authored-by: Antoine Pitrou <pitrou@free.fr>

@rok rok 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.

I think we can merge if CI is green @pitrou ?

@MashrafeeAryan

Copy link
Copy Markdown
Contributor Author

@MashrafeeAryan Can you fix the lint failure?

I have fixed the lint issue. Thank you so much!

@pitrou

pitrou commented Nov 2, 2026

Copy link
Copy Markdown
Member

Yes, I think so. Thank you @MashrafeeAryan !

@rok
rok merged commit aae29bf into apache:main Nov 2, 2026
58 of 59 checks passed
@rok rok removed the awaiting merge label Nov 2, 2026
@rok

rok commented Nov 2, 2026

Copy link
Copy Markdown
Member

Merged. Thanks for working on this @MashrafeeAryan !

@MashrafeeAryan

Copy link
Copy Markdown
Contributor Author

Thank you so much @rok and @pitrou for guiding me through this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++][Parquet] Make compression adaptive with V2 data pages

3 participants