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-41697: [Go][Parquet] Release BufferWriter when BufferedPageWriter is closed #41698

Merged
merged 3 commits into from
May 20, 2024
Merged
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
7 changes: 6 additions & 1 deletion go/parquet/internal/encoding/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,16 @@ func (b *BufferWriter) Truncate() {
func (b *BufferWriter) Reset(initial int) {
if b.buffer != nil {
b.buffer.Release()
} else {
b.buffer = memory.NewResizableBuffer(b.mem)
}

b.pos = 0
b.offset = 0
b.Reserve(initial)

if initial > 0 {
b.Reserve(initial)
}
}

// Reserve ensures that there is at least enough capacity to write nbytes
Expand Down
42 changes: 42 additions & 0 deletions go/parquet/pqarrow/file_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package pqarrow_test

import (
"bytes"
"math"
"strings"
"testing"

Expand Down Expand Up @@ -87,3 +88,44 @@ func TestFileWriterNumRows(t *testing.T) {
require.NoError(t, writer.Close())
assert.Equal(t, 4, writer.NumRows())
}

func TestFileWriterBuffered(t *testing.T) {
schema := arrow.NewSchema([]arrow.Field{
{Name: "one", Nullable: true, Type: arrow.PrimitiveTypes.Float64},
{Name: "two", Nullable: true, Type: arrow.PrimitiveTypes.Float64},
}, nil)

data := `[
{"one": 1, "two": 2},
{"one": 1, "two": null},
{"one": null, "two": 2},
{"one": null, "two": null}
]`

alloc := memory.NewCheckedAllocator(memory.DefaultAllocator)
defer alloc.AssertSize(t, 0)

record, _, err := array.RecordFromJSON(alloc, schema, strings.NewReader(data))
require.NoError(t, err)
defer record.Release()

output := &bytes.Buffer{}
writer, err := pqarrow.NewFileWriter(
schema,
output,
parquet.NewWriterProperties(
parquet.WithAllocator(alloc),
// Ensure enough space so we can close the writer with rows still buffered
parquet.WithMaxRowGroupLength(math.MaxInt64),
),
pqarrow.NewArrowWriterProperties(
pqarrow.WithAllocator(alloc),
),
)
require.NoError(t, err)

require.NoError(t, writer.WriteBuffered(record))

require.NoError(t, writer.Close())
assert.Equal(t, 4, writer.NumRows())
}
Loading