Skip to content

fix(parquet/metadata): count non-null values from the validity bitmap in UpdateSpaced - #1367

Merged
zeroshade merged 1 commit into
apache:mainfrom
CaptainAni187:fix/nested-null-list-statistics-1366
Oct 13, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
CaptainAni187:fix/nested-null-list-statistics-1366

Conversation

@CaptainAni187

Copy link
Copy Markdown

Rationale for this change

Fixes #1366. Writing a list<timestamp> column whose only row is a null list with statistics enabled produced min = MaxInt64 and max = MinInt64 with HasMinMax() == true, so DuckDB failed to read the file.

UpdateSpaced computed the non-null count as len(values) - numNull. For a nested column the spaced values only cover the leaf slots, but numNull also counts the null list, so the count was 0 - 1 = -1. That skipped the notnull == 0 early return and set min/max from no values. The same miscount also hid real values: a null list next to [5] gave 1 - 1 = 0, so the 5 never reached min/max.

What changes are included in this PR?

UpdateSpaced counts the non-null values with bitutil.CountSetBits over validBits, the bitmap it already uses for getMinMaxSpaced. The change is in statistics_types.gen.go.tmpl, and statistics_types.gen.go is regenerated with go generate.

Are these changes tested?

Yes. TestWriteArrowNestedNullListStatistics writes a column with only a null list and one with a null list followed by [5], on both data page versions. It checks the null count, the number of values and that min/max are absent or 5. All four cases fail on main and pass with the fix.

go test ./parquet/... ./arrow/compute/... passes with the testing submodules, and golangci-lint reports no issues.

Are there any user-facing changes?

Nested columns with null lists no longer get invalid min/max statistics, and their non-null values are included in min/max.

… in UpdateSpaced

UpdateSpaced computed the non-null count as len(values) - numNull. For a
nested column, the spaced values only cover the leaf slots, while numNull
also counts nulls at a parent level such as a null list. A column holding
only a null list got -1 and wrote the min/max sentinels as statistics, and
a null list next to a value got 0 and dropped the value's min/max.

Fixes #1366
@zeroshade
zeroshade force-pushed the fix/nested-null-list-statistics-1366 branch from bd1d2ba to d5cd8ee Compare October 13, 2026 13:43

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

LGTM — for nested columns numNull includes null lists that have no slot in spacedValues, so len(values) - numNull could go negative (bogus MaxInt64/MinInt64 min/max with HasMinMax() == true) or drop real values. Counting set bits in validBits over the spaced values matches what getMinMaxSpaced iterates and mirrors the C++ writer, which passes the non-null leaf count explicitly. I confirmed all four TestWriteArrowNestedNullListStatistics cases fail without the fix and pass with it, go generate reproduces the committed statistics_types.gen.go, and the full parquet/... suite passes locally.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Arrow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

More on how Apache Arrow handles maintainer review:
CONTRIBUTING.md.

@zeroshade
zeroshade merged commit 50fb078 into apache:main Oct 13, 2026
23 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.

[Parquet] Invalid statistics for nested timestamp field

2 participants