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 1eb101b0 fix(parquet/internal/encoding): clear buffered RLE booleans
after each flush (#1539)
1eb101b0 is described below
commit 1eb101b0db2121c85d8a723a532b32a146d860e3
Author: Harrison Crosse <[email protected]>
AuthorDate: Thu Nov 12 12:00:14 2026 -0500
fix(parquet/internal/encoding): clear buffered RLE booleans after each
flush (#1539)
### Rationale for this change
Writing boolean columns with `RLE` repeats earlier values on later pages
and inflates page counts.
### What changes are included in this PR?
`RleBooleanEncoder.FlushValues` clears `bufferedValues` after finishing
the page buffer, matching Arrow C++. Reslicing retains the backing array
for reuse and resets the size estimate for the next page.
`flushBooleanEncoder` drops its manual reset, which is now redundant and
would hide a regression in the benchmark.
### Are these changes tested?
`TestRleBooleanEncoderFlushStartsNewPage` flushes two pages and checks
that the second decodes to `[false true]`. It fails on main with `[true
true]` and passes with this change. The issue's reproduction reads back
the original values with this change, including through pyarrow.
With Go 1.26.10, vet, the encoding package race tests, full
`./parquet/...` tests with pinned `arrow-testing` and `parquet-testing`
checked out, `golangci-lint` on the `parquet` module and the Release
Audit Tool passed.
### Are there any user-facing changes?
Yes. Boolean columns written with `RLE` retain the correct values across
pages. Files written before this change still contain the repeated
values. There is no API change.
Closes https://github.com/apache/arrow-go/issues/1534.
---
parquet/internal/encoding/boolean_encoder.go | 1 +
.../boolean_encoder_spaced_benchmark_test.go | 4 ----
parquet/internal/encoding/encoding_test.go | 26 ++++++++++++++++++++++
3 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/parquet/internal/encoding/boolean_encoder.go
b/parquet/internal/encoding/boolean_encoder.go
index 0f7fcc8b..df71ffe1 100644
--- a/parquet/internal/encoding/boolean_encoder.go
+++ b/parquet/internal/encoding/boolean_encoder.go
@@ -281,6 +281,7 @@ func (enc *RleBooleanEncoder) FlushValues() (Buffer, error)
{
debug.Assert(n <= rleBufferSizeMax, "num encoded bytes larger than
expected max")
buf := enc.sink.Finish()
binary.LittleEndian.PutUint32(buf.Bytes(), uint32(n))
+ enc.bufferedValues = enc.bufferedValues[:0]
return buf, nil
}
diff --git a/parquet/internal/encoding/boolean_encoder_spaced_benchmark_test.go
b/parquet/internal/encoding/boolean_encoder_spaced_benchmark_test.go
index 092b0c09..d42dfbd9 100644
--- a/parquet/internal/encoding/boolean_encoder_spaced_benchmark_test.go
+++ b/parquet/internal/encoding/boolean_encoder_spaced_benchmark_test.go
@@ -89,8 +89,4 @@ func flushBooleanEncoder(b *testing.B, encoder
booleanSpacedEncoder) {
b.Fatal(err)
}
buf.Release()
-
- if enc, ok := encoder.(*RleBooleanEncoder); ok {
- enc.bufferedValues = enc.bufferedValues[:0]
- }
}
diff --git a/parquet/internal/encoding/encoding_test.go
b/parquet/internal/encoding/encoding_test.go
index a7009b2d..a9c0eb7b 100644
--- a/parquet/internal/encoding/encoding_test.go
+++ b/parquet/internal/encoding/encoding_test.go
@@ -1696,6 +1696,32 @@ func TestRleBooleanEncoderPutSpacedBitmap(t *testing.T) {
assert.Equal(t, expected, out)
}
+func TestRleBooleanEncoderFlushStartsNewPage(t *testing.T) {
+ descr := schema.NewColumn(schema.NewBooleanNode("bool",
parquet.Repetitions.Required, -1), 0, 0)
+ enc := encoding.NewEncoder(parquet.Types.Boolean,
parquet.Encodings.RLE, false, descr, memory.DefaultAllocator)
+ benc := enc.(encoding.BooleanEncoder)
+
+ benc.Put([]bool{true, true, true, false})
+ first, err := enc.FlushValues()
+ require.NoError(t, err)
+ first.Release()
+
+ benc.Put([]bool{false, true})
+ buf, err := enc.FlushValues()
+ require.NoError(t, err)
+ defer buf.Release()
+
+ dec := encoding.NewDecoder(parquet.Types.Boolean,
parquet.Encodings.RLE, descr, memory.DefaultAllocator)
+ bdec := dec.(encoding.BooleanDecoder)
+ require.NoError(t, bdec.SetData(2, buf.Bytes()))
+
+ out := make([]bool, 2)
+ n, err := bdec.Decode(out)
+ require.NoError(t, err)
+ assert.Equal(t, 2, n)
+ assert.Equal(t, []bool{false, true}, out)
+}
+
func TestRleBooleanEncoderPutSpacedBitmapConsistency(t *testing.T) {
descr := schema.NewColumn(schema.NewBooleanNode("bool",
parquet.Repetitions.Optional, -1), 0, 0)