Repository navigation
fix(parquet/metadata): count non-null values from the validity bitmap in UpdateSpaced - #1367
Conversation
… 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
bd1d2ba to
d5cd8ee
Compare
zeroshade
left a comment
There was a problem hiding this comment.
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.
Rationale for this change
Fixes #1366. Writing a
list<timestamp>column whose only row is a null list with statistics enabled producedmin = MaxInt64andmax = MinInt64withHasMinMax() == true, so DuckDB failed to read the file.UpdateSpacedcomputed the non-null count aslen(values) - numNull. For a nested column the spaced values only cover the leaf slots, butnumNullalso counts the null list, so the count was0 - 1 = -1. That skipped thenotnull == 0early return and set min/max from no values. The same miscount also hid real values: a null list next to[5]gave1 - 1 = 0, so the5never reached min/max.What changes are included in this PR?
UpdateSpacedcounts the non-null values withbitutil.CountSetBitsovervalidBits, the bitmap it already uses forgetMinMaxSpaced. The change is instatistics_types.gen.go.tmpl, andstatistics_types.gen.gois regenerated withgo generate.Are these changes tested?
Yes.
TestWriteArrowNestedNullListStatisticswrites 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 or5. 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.