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 eea284eb perf(arrow/array): reuse unchanged dictionaries across
builder arrays (#1444)
eea284eb is described below
commit eea284eb68c2fd0174e2378720c4d1ce254b2e51
Author: Harrison Crosse <[email protected]>
AuthorDate: Wed Nov 4 12:58:50 2026 -0500
perf(arrow/array): reuse unchanged dictionaries across builder arrays
(#1444)
### Rationale for this change
Reading a row group in small batches repeatedly copies the same
dictionary. With `SetReadDict` enabled, `pqarrow` copies the whole
dictionary into every batch, so the cost grows with dictionary size and
batch count.
I measured synthetic input with 2M 25-byte strings in one row group,
with all data pages encoded as `RLE_DICTIONARY`.
`BenchmarkReadDictionaryColumn` in `parquet/pqarrow` runs a smaller
version of this setup. The table shows median times from the original
2M-row program with `SetReadDict` enabled. `K` is the number of distinct
values and `B` is the batch size. The issue describes the full setup.
| `K` | `B` | Main → patched, ns/row | Change |
| --- | ---: | ---: | ---: |
| 10k | 8,192 | 21.480 → 5.846 | -72.78% |
| 10k | 65,536 | 7.198 → 5.924 | -17.70% |
| 100k | 8,192 | 187.95 → 12.68 | -93.26% |
| 100k | 65,536 | 35.11 → 12.49 | -64.43% |
| 1M | 8,192 | 1,972.5 → 162.4 | -91.77% |
| 1M | 65,536 | 362.9 → 145.2 | -59.99% |
Run-to-run spread was 7% to 39% on main. All six rows have p=0.002 in
benchstat with n=6. Main and patched runs were interleaved on one 8-vCPU
VM. I found no significant time change without `SetReadDict`, with one
batch per row group, or with `K=100`.
Allocated bytes fell by about 25% to 95% in the same six cases. For
example, at `K=1M` and `B=8,192` they fell from 7,116 MiB to 366 MiB per
row-group read.
### What changes are included in this PR?
The dictionary builder now keeps the last full dictionary it built. It
returns that dictionary again until new values are added. The builder
drops it on `ResetFull`, on checkpoint restore and on its final
`Release`. After the dictionary grows, the next full dictionary replaces
it. `NewDelta` with a nonzero offset still copies only the new entries.
The `DictionaryBuilder` docs describe the sharing.
Five `TimestampWithOffset` tests in `arrow/extensions` never released
their builders, which now hold a cached dictionary. I added the missing
`Release` calls.
### Are these changes tested?
I added five tests that check:
- Reuse without growth, including null indices. A shared dictionary
stays valid after one of its arrays is released. After growth the
builder rebuilds the dictionary once, then reuses it again.
- Rebuilding after `ResetFull`, even when the dictionary length is
unchanged.
- Empty and nonempty `NewDelta` results with a cached dictionary.
- Shared dictionaries and correct values for `Int64` and
`FixedSizeBinary`.
- Rebuilding after checkpoint restore, even when the dictionary length
is unchanged.
I added a dictionary pointer check to `TestIncrementalReads`. Existing
`TestReadWholeFileDict` covers resets between row groups. Each new test
fails with the matching cache or lifetime bug reintroduced, including
missed invalidation on reset or restore and incorrect delta handling.
On Linux with the Arrow and Parquet test data configured, these pass:
- `go test -tags assert,test ./arrow/array/... ./arrow/extensions/...
./parquet/...`
- `go test -race -tags assert,test ./arrow/array/...
./parquet/pqarrow/...`
- `go vet`, `golangci-lint` and `gofmt -l` on the three changed packages
I also checked the IPC writers with a short test that is not included
here. The stream writer sent one full dictionary and one delta, and the
batches read back equal, as on main. The file writer accepted an
unchanged dictionary and rejected a grown one with the same error as
main.
### Are there any user-facing changes?
Yes. Consecutive arrays from one builder can now share one dictionary
`*Data`. The builder may keep a reference to that dictionary until
`ResetFull` or its final `Release`. A caller that never releases its
builder now retains the cached dictionary even after releasing its
arrays. There is no API change.
Closes https://github.com/apache/arrow-go/issues/1443.
---
arrow/array/dictionary.go | 36 ++++++-
arrow/array/dictionary_internal_test.go | 33 ++++++
arrow/array/dictionary_test.go | 138 ++++++++++++++++++++++++
arrow/extensions/timestamp_with_offset_test.go | 5 +
parquet/pqarrow/dictionary_reader_bench_test.go | 138 ++++++++++++++++++++++++
parquet/pqarrow/encode_dictionary_test.go | 5 +
6 files changed, 354 insertions(+), 1 deletion(-)
diff --git a/arrow/array/dictionary.go b/arrow/array/dictionary.go
index 19661cca..8abc52b5 100644
--- a/arrow/array/dictionary.go
+++ b/arrow/array/dictionary.go
@@ -634,6 +634,17 @@ func createMemoTable(mem memory.Allocator, dt
arrow.DataType) (ret hashing.MemoT
return
}
+// DictionaryBuilder builds dictionary-encoded arrays, adding each distinct
+// value to the dictionary once.
+//
+// Consecutive calls to NewArray or NewDictionaryArray may return arrays that
+// share one dictionary when no new values were added in between. The builder
+// caches the last full dictionary. It drops its reference when that
+// dictionary is replaced, on checkpoint restore, on ResetFull, or on its
+// final Release. Releasing all returned arrays alone does not free the cached
+// dictionary. Release the builder before checking that its allocator is
+// empty. Treat the shared dictionary data as immutable. For example, do not
+// call [arrow.ArrayData.Reset] on it.
type DictionaryBuilder interface {
Builder
@@ -652,6 +663,7 @@ type dictionaryBuilder struct {
deltaOffset int
memoTable hashing.MemoTable
idxBuilder IndexBuilder
+ dict *Data
}
func createDictBuilder[T arrow.ValueType](mem memory.Allocator, idxbldr
IndexBuilder, memo hashing.MemoTable, dt *arrow.DictionaryType, init
arrow.Array) DictionaryBuilder {
@@ -851,6 +863,14 @@ func (b *dictionaryBuilder) Release() {
binmemo.Release()
}
b.memoTable = nil
+ b.releaseDict()
+ }
+}
+
+func (b *dictionaryBuilder) releaseDict() {
+ if b.dict != nil {
+ b.dict.Release()
+ b.dict = nil
}
}
@@ -926,6 +946,7 @@ func (b *dictionaryBuilder) ResetFull() {
b.reset()
b.idxBuilder.NewArray().Release()
b.memoTable.Reset()
+ b.releaseDict()
}
type dictionaryBuilderCheckpoint struct {
@@ -939,6 +960,7 @@ func (c *dictionaryBuilderCheckpoint) capture() {
func (c *dictionaryBuilderCheckpoint) restore() {
c.builder.memoTable.Truncate(c.size)
+ c.builder.releaseDict()
}
func (b *dictionaryBuilder) newCheckpoint() checkpointState {
@@ -1035,7 +1057,19 @@ func (b *dictionaryBuilder) newWithDictOffset(offset
int) (indices, dict *Data,
indices = idxarr.Data().(*Data)
b.deltaOffset = b.memoTable.Size()
- dict, err = GetDictArrayData(b.mem, b.dt.ValueType, b.memoTable, offset)
+ switch {
+ case offset != 0:
+ dict, err = GetDictArrayData(b.mem, b.dt.ValueType,
b.memoTable, offset)
+ case b.dict != nil && b.dict.length == b.deltaOffset:
+ b.dict.Retain()
+ dict = b.dict
+ default:
+ if dict, err = GetDictArrayData(b.mem, b.dt.ValueType,
b.memoTable, 0); err == nil {
+ b.releaseDict()
+ dict.Retain()
+ b.dict = dict
+ }
+ }
b.reset()
indices.Retain()
return
diff --git a/arrow/array/dictionary_internal_test.go
b/arrow/array/dictionary_internal_test.go
index 91f622fd..2df47302 100644
--- a/arrow/array/dictionary_internal_test.go
+++ b/arrow/array/dictionary_internal_test.go
@@ -18,6 +18,7 @@ package array
import (
"math"
+ "strings"
"testing"
"github.com/apache/arrow-go/v18/arrow"
@@ -206,3 +207,35 @@ func BenchmarkCheckIndexBounds(b *testing.B) {
})
}
}
+
+func requireStringDictionary(t *testing.T, mem memory.Allocator, values
string, arr *Dictionary) {
+ t.Helper()
+ expected, _, err := FromJSON(mem, arrow.BinaryTypes.String,
strings.NewReader(values))
+ require.NoError(t, err)
+ defer expected.Release()
+ require.Truef(t, Equal(expected, arr.Dictionary()), "got: %s, expected:
%s", arr.Dictionary(), expected)
+}
+
+func TestDictionaryBuilderCheckpointRestoreRebuildsDictionary(t *testing.T) {
+ mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
+ defer mem.AssertSize(t, 0)
+
+ dictType := &arrow.DictionaryType{IndexType: arrow.PrimitiveTypes.Int8,
ValueType: arrow.BinaryTypes.String}
+ bldr := NewDictionaryBuilder(mem, dictType).(*BinaryDictionaryBuilder)
+ defer bldr.Release()
+ require.NoError(t, bldr.AppendString("a"))
+ checkpoint := bldr.newCheckpoint()
+ checkpoint.capture()
+
+ require.NoError(t, bldr.AppendString("b"))
+ first := bldr.NewDictionaryArray()
+ defer first.Release()
+
+ checkpoint.restore()
+ require.NoError(t, bldr.AppendString("c"))
+ second := bldr.NewDictionaryArray()
+ defer second.Release()
+
+ requireStringDictionary(t, mem, `["a", "b"]`, first)
+ requireStringDictionary(t, mem, `["a", "c"]`, second)
+}
diff --git a/arrow/array/dictionary_test.go b/arrow/array/dictionary_test.go
index e6335189..b75887e0 100644
--- a/arrow/array/dictionary_test.go
+++ b/arrow/array/dictionary_test.go
@@ -756,6 +756,144 @@ func TestStringDictionaryBuilderBigDelta(t *testing.T) {
assert.True(t, array.Equal(strarr3, delta3))
}
+func assertDictArrayJSON(t *testing.T, mem memory.Allocator, dt
*arrow.DictionaryType, indices, dict string, got arrow.Array) {
+ t.Helper()
+ expected, err := array.DictArrayFromJSON(mem, dt, indices, dict)
+ require.NoError(t, err)
+ defer expected.Release()
+ assert.Truef(t, array.Equal(expected, got), "got: %s, expected: %s",
got, expected)
+}
+
+func assertJSONArray(t *testing.T, mem memory.Allocator, dt arrow.DataType,
values string, got arrow.Array) {
+ t.Helper()
+ expected, _, err := array.FromJSON(mem, dt, strings.NewReader(values))
+ require.NoError(t, err)
+ defer expected.Release()
+ assert.Truef(t, array.Equal(expected, got), "got: %s, expected: %s",
got, expected)
+}
+
+func TestDictionaryBuilderReusesUnchangedDictionary(t *testing.T) {
+ mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
+ defer mem.AssertSize(t, 0)
+
+ dictType := &arrow.DictionaryType{IndexType: arrow.PrimitiveTypes.Int8,
ValueType: arrow.BinaryTypes.String}
+ bldr := array.NewDictionaryBuilder(mem,
dictType).(*array.BinaryDictionaryBuilder)
+ defer bldr.Release()
+
+ require.NoError(t, bldr.AppendString("a"))
+ require.NoError(t, bldr.AppendString("b"))
+ first := bldr.NewDictionaryArray()
+
+ require.NoError(t, bldr.AppendString("b"))
+ bldr.AppendNull()
+ second := bldr.NewDictionaryArray()
+ defer second.Release()
+
+ assert.Same(t, first.Data().Dictionary(), second.Data().Dictionary())
+ first.Release()
+
+ require.NoError(t, bldr.AppendString("c"))
+ third := bldr.NewDictionaryArray()
+ defer third.Release()
+ assert.NotSame(t, second.Data().Dictionary(), third.Data().Dictionary())
+
+ require.NoError(t, bldr.AppendString("a"))
+ fourth := bldr.NewDictionaryArray()
+ defer fourth.Release()
+ assert.Same(t, third.Data().Dictionary(), fourth.Data().Dictionary())
+
+ assertDictArrayJSON(t, mem, dictType, `[1, null]`, `["a", "b"]`, second)
+ assertDictArrayJSON(t, mem, dictType, `[2]`, `["a", "b", "c"]`, third)
+ assertDictArrayJSON(t, mem, dictType, `[0]`, `["a", "b", "c"]`, fourth)
+}
+
+func TestDictionaryBuilderResetFullRebuildsDictionary(t *testing.T) {
+ mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
+ defer mem.AssertSize(t, 0)
+
+ dictType := &arrow.DictionaryType{IndexType: arrow.PrimitiveTypes.Int8,
ValueType: arrow.BinaryTypes.String}
+ bldr := array.NewDictionaryBuilder(mem,
dictType).(*array.BinaryDictionaryBuilder)
+ defer bldr.Release()
+
+ require.NoError(t, bldr.AppendString("a"))
+ require.NoError(t, bldr.AppendString("b"))
+ first := bldr.NewDictionaryArray()
+ defer first.Release()
+
+ bldr.ResetFull()
+ require.NoError(t, bldr.AppendString("x"))
+ require.NoError(t, bldr.AppendString("y"))
+ second := bldr.NewDictionaryArray()
+ defer second.Release()
+
+ assertDictArrayJSON(t, mem, dictType, `[0, 1]`, `["a", "b"]`, first)
+ assertDictArrayJSON(t, mem, dictType, `[0, 1]`, `["x", "y"]`, second)
+}
+
+func TestDictionaryBuilderNewDeltaWithReusedDictionary(t *testing.T) {
+ mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
+ defer mem.AssertSize(t, 0)
+
+ dictType := &arrow.DictionaryType{IndexType: arrow.PrimitiveTypes.Int8,
ValueType: arrow.BinaryTypes.String}
+ bldr := array.NewDictionaryBuilder(mem,
dictType).(*array.BinaryDictionaryBuilder)
+ defer bldr.Release()
+
+ require.NoError(t, bldr.AppendString("a"))
+ require.NoError(t, bldr.AppendString("b"))
+ first := bldr.NewDictionaryArray()
+ defer first.Release()
+
+ require.NoError(t, bldr.AppendString("b"))
+ indices, delta, err := bldr.NewDelta()
+ require.NoError(t, err)
+ defer indices.Release()
+ defer delta.Release()
+ assertJSONArray(t, mem, arrow.PrimitiveTypes.Int8, `[1]`, indices)
+ assertJSONArray(t, mem, arrow.BinaryTypes.String, `[]`, delta)
+
+ require.NoError(t, bldr.AppendString("c"))
+ indices2, delta2, err := bldr.NewDelta()
+ require.NoError(t, err)
+ defer indices2.Release()
+ defer delta2.Release()
+ assertJSONArray(t, mem, arrow.PrimitiveTypes.Int8, `[2]`, indices2)
+ assertJSONArray(t, mem, arrow.BinaryTypes.String, `["c"]`, delta2)
+}
+
+func TestDictionaryBuilderReusesDictionaryForValueTypes(t *testing.T) {
+ tests := []struct {
+ valueType arrow.DataType
+ values string
+ }{
+ {arrow.PrimitiveTypes.Int64, `[1, 2, 1]`},
+ {&arrow.FixedSizeBinaryType{ByteWidth: 3}, `["YWJj", "ZGVm",
"YWJj"]`},
+ }
+ for _, tt := range tests {
+ t.Run(tt.valueType.String(), func(t *testing.T) {
+ mem :=
memory.NewCheckedAllocator(memory.DefaultAllocator)
+ defer mem.AssertSize(t, 0)
+
+ values, _, err := array.FromJSON(mem, tt.valueType,
strings.NewReader(tt.values))
+ require.NoError(t, err)
+ defer values.Release()
+ bldr := array.NewDictionaryBuilder(mem,
&arrow.DictionaryType{IndexType: arrow.PrimitiveTypes.Int8, ValueType:
tt.valueType})
+ defer bldr.Release()
+
+ require.NoError(t, bldr.AppendArray(values))
+ first := bldr.NewDictionaryArray()
+ defer first.Release()
+ require.NoError(t, bldr.AppendArray(values))
+ second := bldr.NewDictionaryArray()
+ defer second.Release()
+
+ assert.Same(t, first.Data().Dictionary(),
second.Data().Dictionary())
+ distinct := array.NewSlice(values, 0, 2)
+ defer distinct.Release()
+ assert.Truef(t, array.Equal(distinct,
second.Dictionary()), "got: %s, expected: %s", second.Dictionary(), distinct)
+ })
+ }
+}
+
func TestStringDictionaryBuilderIsNull(t *testing.T) {
mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
defer mem.AssertSize(t, 0)
diff --git a/arrow/extensions/timestamp_with_offset_test.go
b/arrow/extensions/timestamp_with_offset_test.go
index b45a706e..9a6f84bb 100644
--- a/arrow/extensions/timestamp_with_offset_test.go
+++ b/arrow/extensions/timestamp_with_offset_test.go
@@ -280,6 +280,7 @@ func TestTimestampWithOffsetExtensionBuilder(t *testing.T) {
for name, offsetType := range allAllowedOffsetTypes {
t.Run(name, func(t *testing.T) {
builder, _ :=
extensions.NewTimestampWithOffsetBuilder(mem, testTimeUnit, offsetType)
+ defer builder.Release()
builder.Append(testDate0)
builder.AppendNull()
@@ -336,6 +337,7 @@ func
TestTimestampWithOffsetBuilderAppendValuesLeadingNull(t *testing.T) {
t.Run(name, func(t *testing.T) {
builder, err :=
extensions.NewTimestampWithOffsetBuilder(mem, testTimeUnit, offsetType)
require.NoError(t, err)
+ defer builder.Release()
// A leading null as the very first operation on a
fresh builder must not
// corrupt the offsets. Reading every value below would
panic on a
@@ -409,6 +411,7 @@ func TestTimestampWithOffsetBuilderAppendValuesNilValids(t
*testing.T) {
t.Run(name+"/"+validsName, func(t *testing.T) {
builder, err :=
extensions.NewTimestampWithOffsetBuilder(mem, testTimeUnit, offsetType)
require.NoError(t, err)
+ defer builder.Release()
builder.AppendValues([]time.Time{testDate0,
testDate1, testDate2}, valids)
@@ -443,6 +446,7 @@ func TestTimestampWithOffsetBuilderReuseAfterNewArray(t
*testing.T) {
t.Run(name, func(t *testing.T) {
builder, err :=
extensions.NewTimestampWithOffsetBuilder(mem, testTimeUnit, offsetType)
require.NoError(t, err)
+ defer builder.Release()
builder.Append(testDate1)
arr1 := builder.NewArray()
@@ -662,6 +666,7 @@ func TestTimestampWithOffsetTypeBatchIPCRoundTrip(t
*testing.T) {
for name, offsetType := range allAllowedOffsetTypes {
t.Run(name, func(t *testing.T) {
builder, _ :=
extensions.NewTimestampWithOffsetBuilder(mem, testTimeUnit, offsetType)
+ defer builder.Release()
builder.Append(testDate0)
builder.AppendNull()
builder.Append(testDate1)
diff --git a/parquet/pqarrow/dictionary_reader_bench_test.go
b/parquet/pqarrow/dictionary_reader_bench_test.go
new file mode 100644
index 00000000..8a6109f1
--- /dev/null
+++ b/parquet/pqarrow/dictionary_reader_bench_test.go
@@ -0,0 +1,138 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package pqarrow_test
+
+import (
+ "bytes"
+ "context"
+ "fmt"
+ "testing"
+
+ "github.com/apache/arrow-go/v18/arrow"
+ "github.com/apache/arrow-go/v18/arrow/array"
+ "github.com/apache/arrow-go/v18/arrow/memory"
+ "github.com/apache/arrow-go/v18/parquet"
+ "github.com/apache/arrow-go/v18/parquet/file"
+ "github.com/apache/arrow-go/v18/parquet/pqarrow"
+)
+
+func BenchmarkReadDictionaryColumn(b *testing.B) {
+ const rows = 1 << 18
+
+ for _, distinct := range []int{100, 10_000, 100_000} {
+ b.Run(fmt.Sprintf("distinct=%d", distinct), func(b *testing.B) {
+ parquetData := writeDictionaryStringColumn(b,
memory.DefaultAllocator, rows, distinct)
+
+ for _, batchSize := range []int64{8192, 65536} {
+ b.Run(fmt.Sprintf("batch=%d", batchSize),
func(b *testing.B) {
+ b.ReportAllocs()
+ b.SetBytes(int64(len(parquetData)))
+ for b.Loop() {
+ if n := readDictionaryColumn(b,
memory.DefaultAllocator, parquetData, batchSize); n != rows {
+ b.Fatalf("read %d rows,
want %d", n, rows)
+ }
+ }
+ })
+ }
+ })
+ }
+}
+
+// writeDictionaryStringColumn writes rows 25-byte strings with the given
number
+// of distinct values to one row group whose data pages are all dictionary
+// encoded.
+func writeDictionaryStringColumn(tb testing.TB, mem memory.Allocator, rows,
distinct int) []byte {
+ tb.Helper()
+ schema := arrow.NewSchema([]arrow.Field{{Name: "s", Type:
arrow.BinaryTypes.String}}, nil)
+
+ bldr := array.NewStringBuilder(mem)
+ defer bldr.Release()
+ for i := range rows {
+ bldr.Append(fmt.Sprintf("value-%019d", i%distinct))
+ }
+ arr := bldr.NewArray()
+ defer arr.Release()
+ rec := array.NewRecordBatch(schema, []arrow.Array{arr}, int64(rows))
+ defer rec.Release()
+
+ props := parquet.NewWriterProperties(
+ parquet.WithDictionaryPageSizeLimit(64<<20),
+ parquet.WithDictionaryCostFallbackFor("s", false),
+ )
+ var buf bytes.Buffer
+ w, err := pqarrow.NewFileWriter(schema, &buf, props,
pqarrow.DefaultWriterProps())
+ if err != nil {
+ tb.Fatal(err)
+ }
+ if err := w.Write(rec); err != nil {
+ tb.Fatal(err)
+ }
+ if err := w.Close(); err != nil {
+ tb.Fatal(err)
+ }
+
+ pf, err := file.NewParquetReader(bytes.NewReader(buf.Bytes()))
+ if err != nil {
+ tb.Fatal(err)
+ }
+ defer pf.Close()
+ if n := pf.NumRowGroups(); n != 1 {
+ tb.Fatalf("wrote %d row groups, want 1", n)
+ }
+ chunk, err := pf.MetaData().RowGroup(0).ColumnChunk(0)
+ if err != nil {
+ tb.Fatal(err)
+ }
+ for _, s := range chunk.EncodingStats() {
+ if s.PageType != file.PageTypeDictionaryPage && s.Encoding !=
parquet.Encodings.RLEDict {
+ tb.Fatalf("wrote a %s data page, want only %s",
s.Encoding, parquet.Encodings.RLEDict)
+ }
+ }
+ return buf.Bytes()
+}
+
+// readDictionaryColumn reads the first column of parquetData as a dictionary
+// array in batches of batchSize rows and returns the number of rows read.
+func readDictionaryColumn(tb testing.TB, mem memory.Allocator, parquetData
[]byte, batchSize int64) int64 {
+ tb.Helper()
+ pf, err := file.NewParquetReader(bytes.NewReader(parquetData))
+ if err != nil {
+ tb.Fatal(err)
+ }
+ defer pf.Close()
+
+ props := pqarrow.ArrowReadProperties{BatchSize: batchSize}
+ props.SetReadDict(0, true)
+ fr, err := pqarrow.NewFileReader(pf, props, mem)
+ if err != nil {
+ tb.Fatal(err)
+ }
+ rr, err := fr.GetRecordReader(context.Background(), nil, nil)
+ if err != nil {
+ tb.Fatal(err)
+ }
+ defer rr.Release()
+
+ var n int64
+ for rr.Next() {
+ n += rr.RecordBatch().NumRows()
+ }
+ if err := rr.Err(); err != nil {
+ tb.Fatal(err)
+ }
+ return n
+}
diff --git a/parquet/pqarrow/encode_dictionary_test.go
b/parquet/pqarrow/encode_dictionary_test.go
index 7f9a0a09..24960fea 100644
--- a/parquet/pqarrow/encode_dictionary_test.go
+++ b/parquet/pqarrow/encode_dictionary_test.go
@@ -780,10 +780,15 @@ func (ar *ArrowReadDictSuite) TestIncrementalReads() {
ctx := compute.WithAllocator(context.Background(), ar.mem)
+ var dict arrow.ArrayData
for i := 0; i < numReads; i++ {
chunk, err := col.NextBatch(int64(batchSize))
ar.Require().NoError(err)
defer chunk.Release()
+ if i == 0 {
+ dict = chunk.Chunk(0).Data().Dictionary()
+ }
+ ar.Same(dict, chunk.Chunk(0).Data().Dictionary(), "batches of
one row group share a dictionary")
// no need to manually release chunk, like other record readers
// the col reader holds onto the current record and will
release it
// when the next is requested or when the reader is released