xgbtxy opened a new pull request, #1677:
URL: https://github.com/apache/arrow-go/pull/1677

   ### Rationale for this change
   
   `(*variant.Builder).Reset()` resets `b.buf`, `b.dict`, and `b.dictKeys`, but 
does not reset `b.totalDictSize`.
   
   When a `variant.Builder` is reused across `Reset()` calls, `Build()` 
computes `maxSize`, `offsetSize`, and `metadataSize` using the accumulated 
`b.totalDictSize` from all prior builds:
   
   1. Subsequent `Metadata.Bytes()` slices are padded with trailing zero bytes 
(`len(m.Bytes()) > m.SizeBytes()`), and `OffsetSize()` is inflated above 1 byte 
once prior keys exceed 255 bytes even when building a primitive or small-key 
object.
   2. Reusing a `Builder` in a loop eventually causes `Build()` to fail with 
`metadata size too large` once cumulative historical key bytes exceed 128 MiB, 
even if each individual value has a tiny dictionary.
   
   ### What changes are included in this PR?
   
   - Reset `b.totalDictSize = 0` in `(*variant.Builder).Reset()` 
(`parquet/variant/builder.go`).
   - Add `TestBuilderResetClearsTotalDictSize` in 
`parquet/variant/builder_test.go` covering empty metadata after a large-key 
build, small-key metadata after reset, and repeated reset reuse.
   
   ### Are these changes tested?
   
   Yes. Confirmed `TestBuilderResetClearsTotalDictSize` fails before the fix 
(`len(m.Bytes()) == 305`, `OffsetSize() == 2` instead of `3` / `1`) and passes 
after the fix under:
   
   - `go test -race -count=1 -tags "assert,test" ./parquet/variant/...`
   - `go test -count=1 -tags "noasm,assert,test" ./parquet/variant/...`
   - `go vet ./parquet/variant/...` and `gofmt -l`
   
   ### Are there any user-facing changes?
   
   No breaking API changes; `Builder.Reset()` now produces compact metadata 
matching freshly constructed builders and no longer accumulates dictionary byte 
counts across resets.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to