This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git
The following commit(s) were added to refs/heads/main by this push:
new 812c8299 fix(parquet/compress): allocate uncompressed output for short
destinations (#1004)
812c8299 is described below
commit 812c82996a07bebef551c34a1370bd607261cf63
Author: Minh Vu <[email protected]>
AuthorDate: Mon Jul 27 22:01:33 2026 +0200
fix(parquet/compress): allocate uncompressed output for short destinations
(#1004)
The codec contract allows a `nil` or undersized destination and expects
the codec to allocate when needed. The uncompressed codec was just
returning the unchanged destination, which could leave callers with
empty or truncated output.
This switches `Encode`, `EncodeLevel`, and `Decode` to append-based
copying and adds coverage for `nil` and undersized destinations.
Tests: `go test ./parquet/compress`
---
parquet/compress/compress.go | 11 +++--------
parquet/compress/compress_test.go | 13 +++++++++++++
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/parquet/compress/compress.go b/parquet/compress/compress.go
index 835f94e4..30dd1dac 100644
--- a/parquet/compress/compress.go
+++ b/parquet/compress/compress.go
@@ -161,10 +161,7 @@ func (nocodec) NewReader(r io.Reader) io.ReadCloser {
}
func (nocodec) Decode(dst, src []byte) []byte {
- if dst != nil {
- copy(dst, src)
- }
- return dst
+ return append(dst[:0], src...)
}
func (n nocodec) DecodeWithError(dst, src []byte) ([]byte, error) {
@@ -180,13 +177,11 @@ func (writerNopCloser) Close() error {
}
func (nocodec) Encode(dst, src []byte) []byte {
- copy(dst, src)
- return dst
+ return append(dst[:0], src...)
}
func (nocodec) EncodeLevel(dst, src []byte, _ int) []byte {
- copy(dst, src)
- return dst
+ return append(dst[:0], src...)
}
func (nocodec) NewWriter(w io.Writer) io.WriteCloser {
diff --git a/parquet/compress/compress_test.go
b/parquet/compress/compress_test.go
index 9410b2ed..a2b9eb28 100644
--- a/parquet/compress/compress_test.go
+++ b/parquet/compress/compress_test.go
@@ -130,6 +130,19 @@ func TestCompressDataOneShot(t *testing.T) {
}
}
+func TestUncompressedCodecAllocatesDestination(t *testing.T) {
+ codec, err := compress.GetCodec(compress.Codecs.Uncompressed)
+ assert.NoError(t, err)
+ src := []byte("arrow")
+
+ assert.Equal(t, src, codec.Encode(nil, src))
+ assert.Equal(t, src, codec.Encode(make([]byte, 1), src))
+ assert.Equal(t, src, codec.EncodeLevel(nil, src, 0))
+ assert.Equal(t, src, codec.EncodeLevel(make([]byte, 1), src, 0))
+ assert.Equal(t, src, codec.Decode(nil, src))
+ assert.Equal(t, src, codec.Decode(make([]byte, 1), src))
+}
+
func TestGzipCompressBound(t *testing.T) {
codec, err := compress.GetCodec(compress.Codecs.Gzip)
assert.NoError(t, err)