Skip to content

Core, Parquet: Fix null counting for parquet that doesn't have null_c… - #17557

Open
xndai wants to merge 6 commits into
apache:mainfrom
xndai:fix-parquet-missing-null-count
Open

Core, Parquet: Fix null counting for parquet that doesn't have null_c…#17557
xndai wants to merge 6 commits into
apache:mainfrom
xndai:fix-parquet-missing-null-count

Conversation

@xndai

@xndai xndai commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

…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 NULL causing wrong results.

Fix by checking the -1 when sum the nulls. Add corresponding tests.

…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.
@xndai

xndai commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Issue #17558

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

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.

Comment thread parquet/src/test/java/org/apache/iceberg/parquet/TestParquetMissingNullCount.java Outdated
xndai and others added 4 commits August 10, 2026 19:48
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 singhpk234 added this to the Iceberg 1.12.0 milestone Aug 11, 2026

@singhpk234 singhpk234 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 fix @xndai, I added this to 1.12 milestone too keep track of it

Comment thread parquet/src/test/java/org/apache/iceberg/parquet/TestParquetMissingNullCount.java Outdated
// 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);

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.

should we instead assert what the val returned is ? -1 right ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

xndai commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for fix @xndai, I added this to 1.12 milestone too keep track of it

No problem. please also track #17560 - another correctness issue regarding null count.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants