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 12617728 fix(parquet/file): return page errors from ReadBatch and Skip 
(#1560)
12617728 is described below

commit 126177281c11427aa39eebab94a54663c5edf4cc
Author: Harrison Crosse <[email protected]>
AuthorDate: Mon Nov 16 12:57:12 2026 -0500

    fix(parquet/file): return page errors from ReadBatch and Skip (#1560)
    
    ### Rationale for this change
    
    When a `file` column reader cannot read a page, `ReadBatch` and `Skip`
    return no error, and the next call skips the failed page's values.
    
    ### What changes are included in this PR?
    
    `HasNext` stays false after a page error, `ReadBatch` and `Skip` return
    the error, and a successful `SeekToRow` clears it. This also covers
    `processPage` rejections such as decoder `SetData` errors.
    
    This changes the `ReadBatch` contract. It returned a nil error for a
    page it could not open, with the reason available only through `Err()`.
    It now returns the error with any values read before that page.
    `TestALPOnIntegerColumnIsRejected` now expects the returned error.
    
    ### Are these changes tested?
    
    `TestReadBatchStopsAtCorruptPage`, `TestSkipStopsAtCorruptPage` and
    `TestSeekToRowAfterCorruptPage` cover partial results with a persistent
    error, `Skip`, and reading after a seek. All three pass with this
    change, and the `ReadBatch` and `Skip` tests fail on main.
    
    With Go 1.26.10, vet and race tests for `parquet/file` and
    `parquet/pqarrow`, full `go test -race ./parquet/...` with pinned test
    data, `golangci-lint` 2.13.2 and the Release Audit Tool passed.
    
    ### Are there any user-facing changes?
    
    Yes. `ReadBatch` and `Skip` return page errors instead of moving past
    the failed page. There is no API change.
    
    Closes https://github.com/apache/arrow-go/issues/1559.
---
 parquet/file/column_reader.go      | 11 ++++-
 parquet/file/column_reader_test.go | 93 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 99 insertions(+), 5 deletions(-)

diff --git a/parquet/file/column_reader.go b/parquet/file/column_reader.go
index 70024fa3..e6617160 100644
--- a/parquet/file/column_reader.go
+++ b/parquet/file/column_reader.go
@@ -306,6 +306,11 @@ func (c *columnChunkReader) getRepLvlBuffer(sz int64) 
[]int16 {
 // HasNext returns whether there is more data to be read in this column
 // and row group.
 func (c *columnChunkReader) HasNext() bool {
+       // asking the page reader again moves past the failed page, so stay 
stopped
+       // at the first error
+       if c.err != nil {
+               return false
+       }
        if c.numBuffered == 0 || c.numDecoded == c.numBuffered {
                return c.readNewPage() && c.numBuffered != 0
        }
@@ -628,6 +633,7 @@ func (c *columnChunkReader) SeekToRow(rowIdx int64) error {
                return err
        }
 
+       c.err = nil
        c.numBuffered, c.numDecoded = 0, 0
        c.curPage = c.rdr.Page()
        if c.curPage == nil {
@@ -730,7 +736,7 @@ func (c *columnChunkReader) skipRows(nrows int64) error {
                        c.consumeBufferedValues(int64(levelsToSkip))
                }
        }
-       return nil
+       return c.err
 }
 
 type readerFunc func(int64, int64) (int, error)
@@ -760,6 +766,9 @@ func (c *columnChunkReader) readBatch(batchSize int64, 
defLvls, repLvls []int16,
                totalLvls += lvls
                totalRead += read
        }
+       if err == nil {
+               err = c.err
+       }
        return totalLvls, totalRead, err
 }
 
diff --git a/parquet/file/column_reader_test.go 
b/parquet/file/column_reader_test.go
index a0e3557d..7581ed05 100644
--- a/parquet/file/column_reader_test.go
+++ b/parquet/file/column_reader_test.go
@@ -33,6 +33,7 @@ import (
        "github.com/apache/arrow-go/v18/arrow/memory"
        "github.com/apache/arrow-go/v18/internal/utils"
        "github.com/apache/arrow-go/v18/parquet"
+       "github.com/apache/arrow-go/v18/parquet/compress"
        "github.com/apache/arrow-go/v18/parquet/file"
        "github.com/apache/arrow-go/v18/parquet/internal/encoding"
        "github.com/apache/arrow-go/v18/parquet/internal/testutils"
@@ -878,12 +879,9 @@ func TestALPOnIntegerColumnIsRejected(t *testing.T) {
        r := file.NewColumnReader(descr, pages, mem, nil)
        defer r.Close()
        total, read, err := r.(*file.Int32ColumnChunkReader).ReadBatch(4, 
make([]int32, 4), nil, nil)
-       require.NoError(t, err)
+       require.ErrorContains(t, err, "only float and double support ALP 
encoding")
        require.Zero(t, total)
        require.Zero(t, read)
-       // ReadBatch stops rather than returning the failure, as it does for 
any page
-       // it cannot open, so the reason is on the reader.
-       require.ErrorContains(t, r.Err(), "only float and double support ALP 
encoding")
 }
 
 // A mismatched page count must return an error instead of a zero-length read,
@@ -921,6 +919,93 @@ func TestALPPageClaimingTooManyValues(t *testing.T) {
        require.Equal(t, []float64{1.5, 2.5}, values[:read])
 }
 
+func newCorruptPageReader(t *testing.T) *file.Int32ColumnChunkReader {
+       t.Helper()
+       sc := schema.MustGroup(schema.NewGroupNode("schema", 
parquet.Repetitions.Required, schema.FieldList{
+               schema.NewInt32Node("x", parquet.Repetitions.Required, -1),
+       }, -1))
+       props := 
parquet.NewWriterProperties(parquet.WithCompression(compress.Codecs.Gzip),
+               parquet.WithDictionaryDefault(false), 
parquet.WithDataPageSize(1), parquet.WithPageIndexEnabled(true))
+
+       // each WriteBatch call ends in its own page
+       var out bytes.Buffer
+       w, err := file.NewParquetWriterWithError(&out, sc, 
file.WithWriterProps(props))
+       require.NoError(t, err)
+       rg := w.AppendRowGroup()
+       cw, err := rg.NextColumn()
+       require.NoError(t, err)
+       for page := range int32(3) {
+               vals := make([]int32, 10)
+               for i := range vals {
+                       vals[i] = page*10 + int32(i)
+               }
+               _, err = cw.(*file.Int32ColumnChunkWriter).WriteBatch(vals, 
nil, nil)
+               require.NoError(t, err)
+       }
+       require.NoError(t, cw.Close())
+       require.NoError(t, rg.Close())
+       require.NoError(t, w.Close())
+       data := out.Bytes()
+
+       rdr, err := file.NewParquetReader(bytes.NewReader(data))
+       require.NoError(t, err)
+       rgIdx, err := rdr.GetPageIndexReader().RowGroup(0)
+       require.NoError(t, err)
+       oidx, err := rgIdx.GetOffsetIndex(0)
+       require.NoError(t, err)
+       locs := oidx.GetPageLocations()
+       require.Len(t, locs, 3)
+       require.NoError(t, rdr.Close())
+
+       // the last eight bytes of a gzip stream are its CRC-32 and length
+       data[locs[1].Offset+int64(locs[1].CompressedPageSize)-8] ^= 0xff
+
+       mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+       t.Cleanup(func() { mem.AssertSize(t, 0) })
+       rdr, err = file.NewParquetReader(bytes.NewReader(data), 
file.WithReadProps(parquet.NewReaderProperties(mem)))
+       require.NoError(t, err)
+       t.Cleanup(func() { rdr.Close() })
+       col, err := rdr.RowGroup(0).Column(0)
+       require.NoError(t, err)
+       t.Cleanup(func() { col.Close() })
+       return col.(*file.Int32ColumnChunkReader)
+}
+
+func TestReadBatchStopsAtCorruptPage(t *testing.T) {
+       icr := newCorruptPageReader(t)
+
+       vals := make([]int32, 30)
+       total, n, err := icr.ReadBatch(int64(len(vals)), vals, nil, nil)
+       require.ErrorContains(t, err, "invalid checksum")
+       assert.EqualValues(t, 10, total)
+       assert.Equal(t, []int32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, vals[:n])
+
+       total, _, err2 := icr.ReadBatch(int64(len(vals)), vals, nil, nil)
+       assert.Equal(t, err, err2)
+       assert.Zero(t, total)
+       assert.False(t, icr.HasNext())
+}
+
+func TestSkipStopsAtCorruptPage(t *testing.T) {
+       icr := newCorruptPageReader(t)
+
+       _, err := icr.Skip(25)
+       require.ErrorContains(t, err, "invalid checksum")
+}
+
+func TestSeekToRowAfterCorruptPage(t *testing.T) {
+       icr := newCorruptPageReader(t)
+
+       vals := make([]int32, 30)
+       _, _, err := icr.ReadBatch(int64(len(vals)), vals, nil, nil)
+       require.ErrorContains(t, err, "invalid checksum")
+
+       require.NoError(t, icr.SeekToRow(25))
+       _, n, err := icr.ReadBatch(5, vals, nil, nil)
+       require.NoError(t, err)
+       assert.Equal(t, []int32{25, 26, 27, 28, 29}, vals[:n])
+}
+
 func BenchmarkReadInt32Column(b *testing.B) {
        // generate parquet with RLE-dictionary encoded int32 column
        tempdir := b.TempDir()

Reply via email to