Core, Parquet: Fix null counting for parquet that doesn't have null_c… - #17557
Open
xndai wants to merge 6 commits into
Open
Core, Parquet: Fix null counting for parquet that doesn't have null_c…#17557xndai wants to merge 6 commits into
xndai wants to merge 6 commits into
Conversation
…ount stats Parquet's Statistics#getNumNulls returns -1 when null_count is missing from the stats. But our current metrics logic doesn't handle this -1 value specifically, instead it just adds to the existing count. For a single row group the -1 total was dropped because Metrics only keeps non-negative counts. But say we have row group 0 that has one null value and row group 1 doesn't have null_count stats and return -1, we end up counting total null count as 0, which is wrong. A query engine that relys on total null count being 0, can skip the file completely when evaluating predicate like `WHERE c IS NULL` causing wrong results. Fix by checking the -1 when sum the nulls. Add corresponding tests.
3 tasks
Contributor
Author
|
Issue #17558 |
anoopj
reviewed
Aug 9, 2026
anoopj
left a comment
Member
There was a problem hiding this comment.
The core code change looks good to me. This is an important correctness fix - thanks for catching this!
I have a couple of comments on tests.
Address review feedback: the manifest round-trip test does not need the filesystem. Use InMemoryOutputFile and InMemoryFileIO instead of a temp directory, following TestVariantMetrics.
Address review feedback: the variant metrics paths handle a missing null_count too, but had no test for it. Add cases that build a two row group footer where one row group omits the variant column's null_count, covering both the footer null count path and the all-null-variant path that uses the value count instead.
The merge of main dropped the @test annotation from testShreddedStringBoundsAcrossRowGroups (added upstream in apache#17397), so JUnit silently skipped it. Restore the annotation so the test runs again.
singhpk234
reviewed
Aug 11, 2026
singhpk234
left a comment
Contributor
There was a problem hiding this comment.
Thanks for fix @xndai, I added this to 1.12 milestone too keep track of it
| // without accounting for the -1 sentinel, this sums to an incorrect null count of 0 | ||
| Metrics metrics = metrics(block(statsWithoutNullCount(1, 10), 10), block(stats(20, 30, 1), 10)); | ||
|
|
||
| assertThat(metrics.nullValueCounts()).doesNotContainKey(1); |
Contributor
There was a problem hiding this comment.
should we instead assert what the val returned is ? -1 right ?
Contributor
Author
There was a problem hiding this comment.
The -1 is returned from Statistics.getNumNulls() as an internal sentinel to represent unknown state. But when the null count is stored into Metrics, -1 is dropped so here we assert the null value count is unavailable in the map.
Address review feedback: follow the convention of omitting the redundant "test" prefix on test method names.
Contributor
Author
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.
…ount stats
Parquet's Statistics#getNumNulls returns -1 when null_count is missing from the stats. But our current metrics logic doesn't handle this -1 value specifically, instead it just adds to the existing count.
For a single row group the -1 total was dropped because Metrics only keeps non-negative counts. But say we have row group 0 that has one null value and row group 1 doesn't have null_count stats and return -1, we end up counting total null count as 0, which is wrong. A query engine that relays on total null count being 0, can skip the file completely when evaluating predicate like
WHERE c IS NULLcausing wrong results.Fix by checking the -1 when sum the nulls. Add corresponding tests.