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 d9dd6e7a fix(parquet/metadata): count empty strings in byte array 
statistics from Arrow (#1527)
d9dd6e7a is described below

commit d9dd6e7a38c2442cb06f33f5c0a42e395f072168
Author: Harrison Crosse <[email protected]>
AuthorDate: Wed Nov 11 17:59:55 2026 -0500

    fix(parquet/metadata): count empty strings in byte array statistics from 
Arrow (#1527)
    
    ### Rationale for this change
    
    Dictionary column statistics can exclude `""` from their bounds, causing
    readers that prune by statistics to skip matching rows.
    
    ### What changes are included in this PR?
    
    `ByteArrayStatistics.UpdateFromArrow` skips nulls by validity, not
    length. A missing value buffer becomes an empty slice because `nil`
    means an unset bound. This also keeps bytes in null slots out of the
    bounds.
    
    ### Are these changes tested?
    
    `TestDictionaryArrayStatisticsEmptyString` writes dictionary columns and
    checks their stored bounds.
    `TestByteArrayStatisticsUpdateFromArrowSkipsNullValueBytes` checks a
    null slot that still holds bytes. Both tests fail on main and pass with
    this change. The case in the issue produces `min="" max="az"` with this
    change.
    
    With Go 1.26.10, vet, affected `-race -tags assert,test` tests, full `go
    test -tags assert,test ./parquet/...` with pinned test data, lint,
    regeneration and the Release Audit Tool passed.
    
    ### Are there any user-facing changes?
    
    Yes. New files include empty strings and exclude null slots in these
    statistics. Existing files are unchanged. There is no API change.
    
    Closes https://github.com/apache/arrow-go/issues/1524.
---
 parquet/metadata/statistics_test.go           | 22 +++++++++++
 parquet/metadata/statistics_types.gen.go      |  6 ++-
 parquet/metadata/statistics_types.gen.go.tmpl |  8 +++-
 parquet/pqarrow/encode_dictionary_test.go     | 53 +++++++++++++++++++++++++++
 4 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/parquet/metadata/statistics_test.go 
b/parquet/metadata/statistics_test.go
index 4aa1607a..a542706b 100644
--- a/parquet/metadata/statistics_test.go
+++ b/parquet/metadata/statistics_test.go
@@ -820,6 +820,28 @@ func TestFixedLenByteArrayStatisticsUpdateFromArrowMax(t 
*testing.T) {
        assert.Equal(t, "ccc", string(stats.Max()), "max must be computed 
against the running max, not the running min")
 }
 
+func TestByteArrayStatisticsUpdateFromArrowSkipsNullValueBytes(t *testing.T) {
+       mem := memory.DefaultAllocator
+       n, err := schema.NewPrimitiveNode("s", parquet.Repetitions.Optional, 
parquet.Types.ByteArray, -1, -1)
+       require.NoError(t, err)
+       stats := metadata.NewStatistics(schema.NewColumn(n, 1, 0), 
mem).(*metadata.ByteArrayStatistics)
+
+       // ["a", null], where the null slot still spans the byte "b"
+       data := array.NewData(arrow.BinaryTypes.String, 2, []*memory.Buffer{
+               memory.NewBufferBytes([]byte{0b01}),
+               memory.NewBufferBytes(arrow.Int32Traits.CastToBytes([]int32{0, 
1, 2})),
+               memory.NewBufferBytes([]byte("ab")),
+       }, nil, 1, 0)
+       defer data.Release()
+       arr := array.MakeFromData(data)
+       defer arr.Release()
+
+       require.NoError(t, stats.UpdateFromArrow(arr, true))
+       require.True(t, stats.HasMinMax())
+       assert.Equal(t, "a", string(stats.Min()))
+       assert.Equal(t, "a", string(stats.Max()))
+}
+
 type encodedStatProvider struct {
        min, max []byte
 }
diff --git a/parquet/metadata/statistics_types.gen.go 
b/parquet/metadata/statistics_types.gen.go
index f6e93ef4..46c7ddc8 100644
--- a/parquet/metadata/statistics_types.gen.go
+++ b/parquet/metadata/statistics_types.gen.go
@@ -2115,13 +2115,17 @@ func (s *ByteArrayStatistics) UpdateFromArrow(values 
arrow.Array, updateCounts b
                data      = arr.ValueBytes()
                curOffset = int64(0)
        )
+       if data == nil {
+               // minval and maxval treat nil as unset
+               data = []byte{}
+       }
 
        for i := 0; i < arr.Len(); i++ {
                nextOffset := curOffset + int64(arr.ValueLen(i))
                v := data[curOffset:nextOffset]
                curOffset = nextOffset
 
-               if len(v) == 0 {
+               if arr.IsNull(i) {
                        continue
                }
 
diff --git a/parquet/metadata/statistics_types.gen.go.tmpl 
b/parquet/metadata/statistics_types.gen.go.tmpl
index eef1a050..025d61bd 100644
--- a/parquet/metadata/statistics_types.gen.go.tmpl
+++ b/parquet/metadata/statistics_types.gen.go.tmpl
@@ -420,16 +420,20 @@ func (s *{{.Name}}Statistics) UpdateFromArrow(values 
arrow.Array, updateCounts b
     data = arr.ValueBytes()
     curOffset = int64(0)
   )
+  if data == nil {
+    // minval and maxval treat nil as unset
+    data = []byte{}
+  }
 
   for i := 0; i < arr.Len(); i++ {
     nextOffset := curOffset + int64(arr.ValueLen(i))
     v := data[curOffset:nextOffset]
     curOffset = nextOffset
 
-    if len(v) == 0 {
+    if arr.IsNull(i) {
       continue
     }
-    
+
     min = s.minval(min, v)
     max = s.maxval(max, v)
   }
diff --git a/parquet/pqarrow/encode_dictionary_test.go 
b/parquet/pqarrow/encode_dictionary_test.go
index 24960fea..1e2a65bc 100644
--- a/parquet/pqarrow/encode_dictionary_test.go
+++ b/parquet/pqarrow/encode_dictionary_test.go
@@ -128,6 +128,59 @@ func TestDictionaryArrayBloomFilter(t *testing.T) {
        }))
 }
 
+func TestDictionaryArrayStatisticsEmptyString(t *testing.T) {
+       tests := []struct {
+               name       string
+               dictionary string
+               indices    string
+               min, max   string
+       }{
+               {"empty and nonempty", `["", "az"]`, `[0, 1]`, "", "az"},
+               {"only empty referenced", `["", "az"]`, `[0]`, "", ""},
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       mem := 
memory.NewCheckedAllocator(memory.DefaultAllocator)
+                       defer mem.AssertSize(t, 0)
+
+                       dictionary, _, err := array.FromJSON(mem, 
arrow.BinaryTypes.String, strings.NewReader(tt.dictionary))
+                       require.NoError(t, err)
+                       defer dictionary.Release()
+                       indices, _, err := array.FromJSON(mem, 
arrow.PrimitiveTypes.Int32, strings.NewReader(tt.indices))
+                       require.NoError(t, err)
+                       defer indices.Release()
+
+                       dictType := &arrow.DictionaryType{IndexType: 
arrow.PrimitiveTypes.Int32, ValueType: arrow.BinaryTypes.String}
+                       values := array.NewDictionaryArray(dictType, indices, 
dictionary)
+                       defer values.Release()
+                       sc := arrow.NewSchema([]arrow.Field{{Name: "values", 
Type: dictType, Nullable: true}}, nil)
+                       rec := array.NewRecordBatch(sc, []arrow.Array{values}, 
int64(values.Len()))
+                       defer rec.Release()
+
+                       var output bytes.Buffer
+                       writer, err := pqarrow.NewFileWriter(sc, &output,
+                               
parquet.NewWriterProperties(parquet.WithAllocator(mem), 
parquet.WithStats(true)),
+                               
pqarrow.NewArrowWriterProperties(pqarrow.WithAllocator(mem)))
+                       require.NoError(t, err)
+                       require.NoError(t, writer.Write(rec))
+                       require.NoError(t, writer.Close())
+
+                       reader, err := 
file.NewParquetReader(bytes.NewReader(output.Bytes()))
+                       require.NoError(t, err)
+                       defer reader.Close()
+                       chunk, err := 
reader.MetaData().RowGroup(0).ColumnChunk(0)
+                       require.NoError(t, err)
+                       stats, err := chunk.Statistics()
+                       require.NoError(t, err)
+
+                       require.True(t, stats.HasMinMax())
+                       assert.Equal(t, tt.min, string(stats.EncodeMin()))
+                       assert.Equal(t, tt.max, string(stats.EncodeMax()))
+               })
+       }
+}
+
 func TestWriteColumnDataRejectsOutOfBoundsDictionaryIndex(t *testing.T) {
        mem := memory.DefaultAllocator
 

Reply via email to