This is an automated email from the ASF dual-hosted git repository.
laskoviymishka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new e11ba54bc fix(table): keep list view offset width when projecting
arrays (#2670)
e11ba54bc is described below
commit e11ba54bc0db06a3b07466c6a1f86db37c5e4f01
Author: Harrison Crosse <[email protected]>
AuthorDate: Wed Nov 25 03:07:01 2026 -0500
fix(table): keep list view offset width when projecting arrays (#2670)
ToRequestedSchema labeled a list_view column as large_list_view while
reusing its 32 bit offsets and sizes buffers. Arrow then read each pair of
int32 entries as one int64, so the returned array was malformed and
ValidateFull rejected it. A large_list_view column had no case at all and
failed with a nil pointer error inside the schema visitor. Project list_view to
list_view and large_list_view to large_list_view so the buffers keep the width
they were written with.
Signed-off-by: Harrison Crosse <[email protected]>
---
table/arrow_utils.go | 2 ++
table/arrow_utils_test.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/table/arrow_utils.go b/table/arrow_utils.go
index ad75e771f..24401e936 100644
--- a/table/arrow_utils.go
+++ b/table/arrow_utils.go
@@ -1399,6 +1399,8 @@ func (a *arrowProjectionVisitor) List(listType
iceberg.ListType, listArr arrow.A
case arrow.LARGE_LIST:
outType = arrow.LargeListOfField(elemField)
case arrow.LIST_VIEW:
+ outType = arrow.ListViewOfField(elemField)
+ case arrow.LARGE_LIST_VIEW:
outType = arrow.LargeListViewOfField(elemField)
}
diff --git a/table/arrow_utils_test.go b/table/arrow_utils_test.go
index 78fecdde9..80ffce466 100644
--- a/table/arrow_utils_test.go
+++ b/table/arrow_utils_test.go
@@ -1380,6 +1380,61 @@ func TestToRequestedSchemaListLargeTypeCoercion(t
*testing.T) {
})
}
+// Widening the element requires rebuilding the list view type without changing
+// its offset width. Slicing also checks that projection preserves the array
offset.
+func TestToRequestedSchemaListView(t *testing.T) {
+ ctx := context.Background()
+ mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+ defer mem.AssertSize(t, 0)
+
+ rows := []struct {
+ name string
+ viewOf func(arrow.Field) arrow.DataType
+ }{
+ {"list_view", func(f arrow.Field) arrow.DataType { return
arrow.ListViewOfField(f) }},
+ {"large_list_view", func(f arrow.Field) arrow.DataType { return
arrow.LargeListViewOfField(f) }},
+ }
+
+ const data = `[{"nested": [9]}, {"nested": null}, {"nested": []},
{"nested": [1, 2]}]`
+
+ for _, row := range rows {
+ t.Run(row.name, func(t *testing.T) {
+ elem := arrow.Field{Name: "element", Type:
arrow.PrimitiveTypes.Int32, Nullable: false, Metadata: fieldIDMeta("2")}
+ arrowSchema := arrow.NewSchema([]arrow.Field{{
+ Name: "nested", Type: row.viewOf(elem),
Nullable: true, Metadata: fieldIDMeta("1"),
+ }}, nil)
+
+ rec, _, err := array.RecordFromJSON(mem, arrowSchema,
strings.NewReader(data))
+ require.NoError(t, err)
+ defer rec.Release()
+
+ sliced := rec.NewSlice(1, 4)
+ defer sliced.Release()
+
+ fileSchema := iceberg.NewSchema(0, iceberg.NestedField{
+ ID: 1, Name: "nested", Type:
iceberg.NewListType(2, iceberg.PrimitiveTypes.Int32, true), Required: false,
+ })
+ requested := iceberg.NewSchema(0, iceberg.NestedField{
+ ID: 1, Name: "nested", Type:
iceberg.NewListType(2, iceberg.PrimitiveTypes.Int64, true), Required: false,
+ })
+
+ out, err :=
table.ToRequestedSchema(compute.WithAllocator(ctx, mem), requested, fileSchema,
sliced, table.SchemaOptions{IncludeFieldIDs: true})
+ require.NoError(t, err)
+ defer out.Release()
+
+ got := out.Column(0)
+ require.NoError(t, array.ValidateFull(got))
+
+ wantType := row.viewOf(arrow.Field{Name: "element",
Type: arrow.PrimitiveTypes.Int64, Nullable: false, Metadata: fieldIDMeta("2")})
+ want, _, err := array.FromJSON(mem, wantType,
strings.NewReader(`[null, [], [1, 2]]`))
+ require.NoError(t, err)
+ defer want.Release()
+
+ assert.True(t, array.Equal(want, got), "want %s, got
%s", want, got)
+ })
+ }
+}
+
func TestToRequestedSchemaListOfStructNoLeak(t *testing.T) {
ctx := context.Background()
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())