Skip to content

fix: treat missing Parquet null counts as zero for files from parquet-rs before 53.1.0 - #27546

Open
Omkar-Wagholikar wants to merge 10 commits into
apache:mainfrom
Omkar-Wagholikar:fix/parquet-legacy-null-counts
Open

Omkar-Wagholikar wants to merge 10 commits into
apache:mainfrom
Omkar-Wagholikar:fix/parquet-legacy-null-counts

Conversation

@Omkar-Wagholikar

@Omkar-Wagholikar Omkar-Wagholikar commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes issue #25253

Rationale for this change

(After #25242) A missing Parquet null_count is treated as 'unknown'. That is right in general, but parquet-rs before 53.1.0 left out null_count whenever it was zero. For files from those writers, including DataFusion before 42.1.0, queries lost:

  • IS NULL row-group pruning
  • COUNT(col) answered from metadata
  • sort-pushdown Exact
  • TopK NULLS FIRST runtime pruning

What changes are included in this PR?

  • missing_null_counts_are_zero(&FileMetaData) decides once per file from created_by. It returns true for parquet-rs below 53.1 and datafusion below 42.1. Any other writer, custom string or unparseable value returns false, so those files keep the fix: preserve missing Parquet null counts #25242 behavior.
  • The result feeds StatisticsConverter::with_missing_null_counts_as_zero in row-group pruning (static, inverted and runtime TopK) and in statistics_from_parquet_metadata.
  • prune_by_statistics, which has no footer, stays conservative.
  • The existing footer-rewrite test fixture is split into a shared replace_footer helper that the new test uses.

What is the testing strategy for this PR?

  • Unit tests cover the created_by parsing, including the 53.0/53.1 and 42.0/42.1 boundaries and malformed strings. They also cover file statistics and row-group pruning for legacy and non-legacy writers.
  • missing_null_count_is_zero_for_legacy_writers in datafusion/core/tests/parquet/dynamic_row_group_pruning.rs rewrites a real file's footer. For legacy writers WHERE v IS NULL prunes 2 of 3 row groups; for others it prunes none. Results match in every case. The test fails without the fix.
  • This can't be an .slt test, because it needs a hand-edited footer.

Are there any user-facing changes?

  • Queries over affected legacy files regain pruning and metadata-only optimizations.
  • The 57.0.0 upgrade guide includes a note about this behavior.
  • No API changes.

I haven't benchmarked this. It restores optimizations rather than adding new ones.

I used Claude Code to help find the code and write tests. I have written, reviewed and tested most of the code myself.

@Omkar-Wagholikar

Copy link
Copy Markdown
Contributor Author

Please ignore the spell check error, it's from a comment

@Omkar-Wagholikar

Copy link
Copy Markdown
Contributor Author

Hi @jayzhan211, @kumarUjjawal, @rluvaton,
When possible, could you please review/ comment on this PR?

@kumarUjjawal
kumarUjjawal self-requested a review November 24, 2026 03:35

@jayzhan211 jayzhan211 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Omkar-Wagholikar thanks for picking this up! Two answers to your questions:

  • Page-index null counts don't need this change. parquet-rs before 53.1.0 always wrote ColumnIndex.null_counts, zeros included (ColumnIndexBuilder::build_to_thrift in 52.2.0 passes the whole Vec), so only row-group statistics are affected.
  • Since 56.0.0 is released, the upgrade-guide entry from #25242 tells 56 users to rewrite their files, and that stays true for 56. Could you add a short note to docs/source/library-user-guide/upgrading/57.0.0.md, so people upgrading to 57 know they don't need to rewrite? For example:
### Missing Parquet null counts from older parquet-rs writers mean zero again

DataFusion 56.0.0 started treating an omitted Parquet `null_count` as unknown.
parquet-rs before 53.1.0, including DataFusion before 42.1.0, omitted only zero
counts, so DataFusion now reads a missing count as zero for files whose
`created_by` names one of those writers. `IS NULL` row-group pruning,
`COUNT(column)` from metadata, sort elimination and `NULLS FIRST` TopK pruning
return for these files without rewriting them. Files from other writers keep
the 56.0.0 behavior.

updated: docs, dyna row grp pruning tests and metadata comments
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Nov 28, 2026
@Omkar-Wagholikar

Copy link
Copy Markdown
Contributor Author

Thanks @jayzhan211, I've addressed all of your comments in d2bc344:

  • Added 'missing_null_count_is_zero_for_runtime_topk_pruning' for the TopK path, as well as the fully-matched assertion. Both fail when the corresponding flag is forced to false.
  • Updated the comment in metadata.rs.
  • Updated the documentation to show the upgrade note in 57.0.0.md.
    Thanks for confirming that page-index null counts need no change. Could you take another look when you have time?

@jayzhan211 jayzhan211 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the updates! Optional: the description still asks about page-index null counts and says no upgrade note was added. Could you drop those two lines and mention the 57.0.0 upgrade note under user-facing changes, since the description becomes the squash commit message?

@Omkar-Wagholikar

Copy link
Copy Markdown
Contributor Author

Hi, thanks for pointing it out! I had missed updating the description. It is updated now.

@jayzhan211
jayzhan211 added this pull request to the merge queue Nov 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 28, 2026
@alamb

alamb commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

I am worried about this change causing hard to diagnose / subtle wrong results. I also think parsing the created by field is pretty brittle as there is no guarantee that people didn't override the created by field

So basically I am wondering why both to (try) and fix this issue?

@Omkar-Wagholikar

Copy link
Copy Markdown
Contributor Author

Thanks @alamb these are fair concerns. The motivation is basically just the issue:#25253

On the risk: you're right that created_by can be overridden (WriterProperties::set_created_by, and DataFusion exposes it too). The change only applies when created_by is exactly parquet-rs/datafusion with a legacy version, and every other or unparseable value keeps the 56.0.0 behavior. The wrong-result case needs a file that claims a legacy writer but has counts missing for another reason, such as a tampered footer.

If you'd still rather not trust created_by, I could put this behind an opt-in config (default off), so only users who know their files come from legacy writers enable it. Or I'm happy to close this if you and @jayzhan211 think the risk isn't worth it. Which would you prefer?

@jayzhan211

Copy link
Copy Markdown
Contributor

@alamb the reason to bother: since 56.0, files from parquet-rs before 53.1 (including DataFusion before 42.1) lose several optimizations, and the only fix we offer is rewriting the data. This PR reads a missing count as zero only for files from those writers, which never left out a non-zero count. Are you OK merging it, or would you rather park it until a user reports the slowdown?

  • What 56.0 costs those files: on nullable columns, IS NULL pruning, COUNT(col) from metadata, sort elimination and NULLS FIRST TopK pruning. Those writers left out null_count only when it was zero (arrow-rs#6490), which covers most parquet-rs files written before October 2024.
  • Wrong results: need a file whose created_by names one of those old writers and that leaves out a non-zero count. Those writers never wrote that. parquet-rs 53.1 and later always write the count, so a current writer with an overridden created_by changes nothing. The bug fix: preserve missing Parquet null counts #25242 fixed (Parquet runtime pruning can drop NULLS FIRST TopK rows when null_count is missing #25239) was found by reading the code, not on a real file.
  • Brittle parsing: a missing, custom or unparseable created_by gets the 56.0 behavior, so a parsing mistake costs speed, not correctness.
  • Compared with 55.x: 55 read every missing count as zero, for every writer, in row-group pruning and file statistics. This PR does that only for the two writer ranges above.

No one has reported the slowdown yet, but 56.0 is less than two weeks old.

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

Labels

core Core DataFusion crate datasource Changes to the datasource crate documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants