fix(parquet/metadata): do not pre-set hasDistinctCount in stat factories#807
Open
SAY-5 wants to merge 1 commit into
Open
fix(parquet/metadata): do not pre-set hasDistinctCount in stat factories#807SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
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.
Rationale for this change
Fixes #806. The
New*Statisticsfactories inparquet/metadata/statistics_types.gen.goinitializehasDistinctCount: trueat construction time, so every fresh stat object reports a distinct count of 0.Encode()then unconditionally callsenc.SetDistinctCount(0), which makes the writer emitdistinct_count: 0in bothColumnChunk.metadata.statisticsandDataPageHeader.statisticsfor every column, even when no distinct count has been computed.The Parquet thrift
Statistics.distinct_countfield is OPTIONAL. Per spec semantics, it must be absent when unknown. Emitting 0 conflates "no distinct values" with "we don't know" and causes byte-asymmetry against parquet-cpp (pyarrow), which leaves the field unset for the same input.IncDistinct()is the only call site that should fliphasDistinctCountto true, and grepping the repo confirms it is never invoked from the writer paths, so flipping the default is safe.What changes are included in this PR?
hasDistinctCount: truefrom the factory initializer instatistics_types.gen.go.tmpland regeneratestatistics_types.gen.go.hasNullCount: trueis kept as-is (its semantics differ:IncNullsis called per page andnull_count: 0is meaningful for a writer that observes zero nulls).TestNewStatisticsDistinctCountUnsetcovering Int32/Int64/Float32/Float64/Boolean/ByteArray, asserting bothHasDistinctCount()andEncode().HasDistinctCountstart false and flip to true afterIncDistinct.Are these changes tested?
Yes. The new test fails on master (HasDistinctCount returns true on a fresh stat object) and passes after the fix.
go test ./parquet/metadata/...is green.Are there any user-facing changes?
Yes, writers that previously emitted
distinct_count: 0for every column will now omit the field, matching the spec and parquet-cpp. Readers already tolerate both, so this is a wire-format normalization, not a breaking change for downstream consumers.