hcrosse opened a new issue, #1534:
URL: https://github.com/apache/arrow-go/issues/1534
### Describe the bug, including details regarding any error messages,
version, and platform.
Writing booleans with `RLE` and more than one data page per column chunk
writes wrong values. Both arrow-go and pyarrow read the affected file back with
values from earlier pages instead of the values written.
I reproduced this on v18.8.0 and main, with Go 1.26.10 on macOS arm64. This
affects callers who opt into `RLE` for boolean columns. The default encoding is
`PLAIN`.
**Key calls and results**
For a table with one boolean column `b` containing `[true true true true
false false false false]`, these settings write two pages of four values:
```go
props := parquet.NewWriterProperties(
parquet.WithEncodingFor("b", parquet.Encodings.RLE),
parquet.WithDataPageSize(1),
parquet.WithBatchSize(4),
)
pqarrow.WriteTable(tbl, &buf, 8, props, pqarrow.DefaultWriterProps())
got, _ := pqarrow.ReadTable(context.Background(),
bytes.NewReader(buf.Bytes()), nil, pqarrow.ArrowReadProperties{}, mem)
```
Both versions produce:
```text
data pages: 2
wrote: [true true true true false false false false]
read: [true true true true true true true true]
```
Expected:
```text
read: [true true true true false false false false]
```
pyarrow 26.0.1 also reads the v18.8.0 file as eight `True` values, so the
error is in the written file, not just arrow-go's reader.
With 10,000 booleans, `WithDataPageSize(256)` and `WithBatchSize(64)`, main
writes 146 pages because every batch after the first 768 values flushes another
page. Clearing the buffer after each flush produces 14 pages.
**Cause**
`RleBooleanEncoder.FlushValues` encodes `bufferedValues` but never clears
it. Page 2 contains page 1's four values followed by its own four, while its
header declares only four values. Readers therefore decode page 1's values
again.
https://github.com/apache/arrow-go/blob/7e088cdf58c2bb6388deed332295c1b83ab99f98/parquet/internal/encoding/boolean_encoder.go#L267-L286
The size estimate also uses the accumulated buffer, so it stays above the
page size after the first flush:
https://github.com/apache/arrow-go/blob/7e088cdf58c2bb6388deed332295c1b83ab99f98/parquet/internal/encoding/boolean_encoder.go#L258-L265
https://github.com/apache/arrow-go/blob/7e088cdf58c2bb6388deed332295c1b83ab99f98/parquet/file/column_writer.go#L281-L301
Arrow C++'s `RleBooleanEncoder::FlushValues` clears
`buffered_append_values_` after finishing each page:
https://github.com/apache/arrow/blob/976779b2aac587f51b87c3bd2e6ae4c36f75ab6c/cpp/src/parquet/encoder.cc#L1823-L1846
I have a patch with tests and can open a PR.
### Component(s)
Parquet
--
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]