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 f8a38985 fix(parquet/file): keep every FlushCurrentPage error for
later Close (#1621)
f8a38985 is described below
commit f8a38985f88007857957d43c2e0850a3229f537a
Author: Ayaan <[email protected]>
AuthorDate: Fri Nov 20 03:55:42 2026 +0530
fix(parquet/file): keep every FlushCurrentPage error for later Close (#1621)
### Rationale for this change
Follow-up to #1597, covering the optional point @zeroshade raised in his
review. #1597 keeps page-write errors on the column writer. Other errors
from `FlushCurrentPage`, such as `FlushValues`, the page size check or
`getPageStatistics`, were returned without being kept, so a later column
`Close` could finish the chunk with missing data.
### What changes are included in this PR?
`FlushCurrentPage` now records its error with `recordError`, as #1597
does for page writes. That covers flushes triggered by `WriteBatch`,
`WriteBatchSpaced`, the bitmap, dictionary-index and Arrow write paths,
explicit `FlushCurrentPage` calls and `FlushBufferedDataPages`. I did it
in `FlushCurrentPage` rather than in each recover handler so one change
covers the template, generated and hand-written writers, and unrelated
panics from bad input are not kept. Happy to move it if you prefer the
handlers. `recordError` keeps the first error, so column `Close` returns
the first saved error on every call.
### Are these changes tested?
Two tests make the first `FlushValues` fail (once, through `WriteBatch`
and through an explicit `FlushCurrentPage`). Both check column and file
`Close` and that zero bytes are appended after the failure. The batch
test also checks repeated closes, row group `Close` and that no readable
footer is written. Both fail on main and pass with this change.
```sh
go test -short ./parquet/...
go test -race ./parquet/file ./parquet/pqarrow
golangci-lint run ./parquet/file/...
```
`go generate ./parquet/file` leaves the diff unchanged.
### Are there any user-facing changes?
After an error returned by `FlushCurrentPage`, column `Close` returns
the saved error and the file writer does not write the footer. Row group
`Close` may still report an earlier validation error first.
---
parquet/file/column_writer.go | 6 +++
parquet/file/page_writer_internal_test.go | 68 +++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+)
diff --git a/parquet/file/column_writer.go b/parquet/file/column_writer.go
index 8d035757..c9ce8381 100644
--- a/parquet/file/column_writer.go
+++ b/parquet/file/column_writer.go
@@ -333,7 +333,13 @@ func (w *columnWriter)
commitWriteAndCheckPageLimit(numLevels, numValues int64)
return nil
}
+// FlushCurrentPage keeps any failure (not only page writes) so a later Close
+// cannot finish a chunk that is missing data.
func (w *columnWriter) FlushCurrentPage() error {
+ return w.recordError(w.flushCurrentPage())
+}
+
+func (w *columnWriter) flushCurrentPage() error {
var (
defLevelsRLESize int32 = 0
repLevelsRLESize int32 = 0
diff --git a/parquet/file/page_writer_internal_test.go
b/parquet/file/page_writer_internal_test.go
index 087617f3..b65795f4 100644
--- a/parquet/file/page_writer_internal_test.go
+++ b/parquet/file/page_writer_internal_test.go
@@ -26,7 +26,9 @@ import (
"github.com/apache/arrow-go/v18/arrow/memory"
"github.com/apache/arrow-go/v18/parquet"
"github.com/apache/arrow-go/v18/parquet/compress"
+ "github.com/apache/arrow-go/v18/parquet/internal/encoding"
"github.com/apache/arrow-go/v18/parquet/internal/encryption"
+ "github.com/apache/arrow-go/v18/parquet/schema"
"github.com/stretchr/testify/require"
)
@@ -169,3 +171,69 @@ func
TestSerializedPageWriterEncryptionRejectsMoreThanMaxInt16Pages(t *testing.T
require.Error(t, err)
require.Contains(t, err.Error(), "encrypted parquet files cannot have
more than 32767 pages per chunk")
}
+
+// failingFlushEncoder fails its first FlushValues call and works afterwards,
+// so only a kept error can make a later Close fail.
+type failingFlushEncoder struct {
+ encoding.Int32Encoder
+ failed bool
+}
+
+func (e *failingFlushEncoder) FlushValues() (encoding.Buffer, error) {
+ if !e.failed {
+ e.failed = true
+ return nil, errors.New("flush values failed")
+ }
+ return e.Int32Encoder.FlushValues()
+}
+
+// A FlushCurrentPage failure other than a page write must also stay on the
+// column, so Close does not finish a chunk that is missing data.
+func TestWriteBatchFlushErrorIsKeptForClose(t *testing.T) {
+ sc, err := schema.NewGroupNode("schema", parquet.Repetitions.Required,
+ schema.FieldList{schema.NewInt32Node("col",
parquet.Repetitions.Required, -1)}, -1)
+ require.NoError(t, err)
+ var buf bytes.Buffer
+ props :=
parquet.NewWriterProperties(parquet.WithDictionaryDefault(false),
parquet.WithDataPageSize(1))
+ writer := NewParquetWriter(&buf, sc, WithWriterProps(props))
+ rg := writer.AppendRowGroup()
+ col, err := rg.NextColumn()
+ require.NoError(t, err)
+ w := col.(*Int32ColumnChunkWriter)
+ w.currentEncoder = &failingFlushEncoder{Int32Encoder:
w.currentEncoder.(encoding.Int32Encoder)}
+
+ _, err = w.WriteBatch([]int32{1, 2, 3}, nil, nil)
+ require.ErrorContains(t, err, "flush values failed")
+ failedSize := buf.Len()
+ for i := 0; i < 2; i++ {
+ require.ErrorContains(t, w.Close(), "flush values failed",
"column close %d", i)
+ require.ErrorContains(t, rg.Close(), "flush values failed",
"row group close %d", i)
+ require.ErrorContains(t, writer.Close(), "flush values failed",
"file close %d", i)
+ }
+ require.Equal(t, failedSize, buf.Len(), "close must not append a
footer")
+ _, readErr := NewParquetReader(bytes.NewReader(buf.Bytes()))
+ require.Error(t, readErr, "failed writes must not produce a readable
footer")
+}
+
+// The exported FlushCurrentPage keeps its failure too.
+func TestExplicitFlushCurrentPageErrorIsKeptForClose(t *testing.T) {
+ sc, err := schema.NewGroupNode("schema", parquet.Repetitions.Required,
+ schema.FieldList{schema.NewInt32Node("col",
parquet.Repetitions.Required, -1)}, -1)
+ require.NoError(t, err)
+ var buf bytes.Buffer
+ props :=
parquet.NewWriterProperties(parquet.WithDictionaryDefault(false))
+ writer := NewParquetWriter(&buf, sc, WithWriterProps(props))
+ rg := writer.AppendRowGroup()
+ col, err := rg.NextColumn()
+ require.NoError(t, err)
+ w := col.(*Int32ColumnChunkWriter)
+ _, err = w.WriteBatch([]int32{1, 2, 3}, nil, nil)
+ require.NoError(t, err)
+ w.currentEncoder = &failingFlushEncoder{Int32Encoder:
w.currentEncoder.(encoding.Int32Encoder)}
+
+ require.ErrorContains(t, w.FlushCurrentPage(), "flush values failed")
+ failedSize := buf.Len()
+ require.ErrorContains(t, w.Close(), "flush values failed")
+ require.ErrorContains(t, writer.Close(), "flush values failed")
+ require.Equal(t, failedSize, buf.Len(), "close must not append a
footer")
+}