Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-43605: [Go][Parquet] Recover from panic in file reader #43607

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/scripts/go_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ go test $testargs -tags $TAGS,noasm ./...
popd

export PARQUET_TEST_DATA=${1}/cpp/submodules/parquet-testing/data
export PARQUET_TEST_BAD_DATA=${1}/cpp/submodules/parquet-testing/bad_data
export ARROW_TEST_DATA=${1}/testing/data
pushd ${source_dir}/parquet

Expand Down
5 changes: 2 additions & 3 deletions go/parquet/internal/utils/bit_packing_avx2_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ func _unpack32_avx2(in, out unsafe.Pointer, batchSize, nbits int) (num int)

func unpack32Avx2(in io.Reader, out []uint32, nbits int) int {
batch := len(out) / 32 * 32
if batch <= 0 {
n := batch * nbits / 8
if n <= 0 {
return 0
}

n := batch * nbits / 8

buffer := bufferPool.Get().(*bytes.Buffer)
defer bufferPool.Put(buffer)
buffer.Reset()
Expand Down
5 changes: 2 additions & 3 deletions go/parquet/internal/utils/bit_packing_neon_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ func _unpack32_neon(in, out unsafe.Pointer, batchSize, nbits int) (num int)

func unpack32NEON(in io.Reader, out []uint32, nbits int) int {
batch := len(out) / 32 * 32
if batch <= 0 {
n := batch * nbits / 8
if n <= 0 {
return 0
}

n := batch * nbits / 8

buffer := bufferPool.Get().(*bytes.Buffer)
defer bufferPool.Put(buffer)
buffer.Reset()
Expand Down
7 changes: 7 additions & 0 deletions go/parquet/pqarrow/file_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/apache/arrow/go/v18/arrow/array"
"github.com/apache/arrow/go/v18/arrow/arrio"
"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/file"
"github.com/apache/arrow/go/v18/parquet/schema"
Expand Down Expand Up @@ -332,6 +333,12 @@ func (fr *FileReader) ReadRowGroups(ctx context.Context, indices, rowGroups []in
for i := 0; i < np; i++ {
go func() {
defer wg.Done()
defer func() {
if pErr := recover(); pErr != nil {
err := utils.FormatRecoveredError("panic while reading", pErr)
results <- resultPair{err: err}
}
}()
for {
select {
case r, ok := <-ch:
Expand Down
34 changes: 34 additions & 0 deletions go/parquet/pqarrow/file_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -373,3 +374,36 @@ func TestFileReaderColumnChunkBoundsErrors(t *testing.T) {
assert.ErrorContains(t, tooHighErr, fmt.Sprintf("there are only %d columns", schema.NumFields()))
}
}

func TestReadParquetFile(t *testing.T) {
dir := os.Getenv("PARQUET_TEST_BAD_DATA")
if dir == "" {
t.Skip("no path supplied with PARQUET_TEST_BAD_DATA")
}
assert.DirExists(t, dir)
filename := path.Join(dir, "ARROW-GH-43605.parquet")
ctx := context.TODO()

mem := memory.NewCheckedAllocator(memory.DefaultAllocator)

rdr, err := file.OpenParquetFile(
filename,
false,
file.WithReadProps(parquet.NewReaderProperties(mem)),
)
require.NoError(t, err)
defer func() {
if err2 := rdr.Close(); err2 != nil {
t.Errorf("unexpected error: %v", err2)
}
}()

arrowRdr, err := pqarrow.NewFileReader(rdr, pqarrow.ArrowReadProperties{
Parallel: false,
BatchSize: 0,
}, mem)
require.NoError(t, err)

_, err = arrowRdr.ReadTable(ctx)
assert.NoError(t, err)
}
Loading