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 a5ae7700 feat(arrow/compute/exprs): select list view elements per row
in `ListElementRef` (#1595)
a5ae7700 is described below
commit a5ae77001a42eb6d86868aa3017b33cb2d2b134f
Author: Harrison Crosse <[email protected]>
AuthorDate: Tue Nov 17 14:38:08 2026 -0500
feat(arrow/compute/exprs): select list view elements per row in
`ListElementRef` (#1595)
### Rationale for this change
Since #1586, `ListElementRef` selects an element per row from list
arrays. It still rejects `list_view` and `large_list_view` arrays,
although `compute.ListElement` supports them.
### What changes are included in this PR?
`arrayStep` passes both types to `compute.ListElement`, which selects an
element using each row's offset and size. The scalar path is unchanged.
### Are these changes tested?
I added `list view out of order and overlapping`, `list view sliced` and
`error past the end of one list view` rows in
`TestListElementRefPerRow`, plus their `large_list_view` equivalents.
The sliced rows include a null, and the error rows ask for a child value
that exists but lies outside the row's view. All six fail on main with
the type rejection and pass with this change. The nine existing subtests
pass on both.
On macOS arm64 with Go 1.26.10, `go test -race -tags assert
./arrow/compute/exprs/...` and `golangci-lint` 2.13.2 on
`./arrow/compute/exprs/...` passed.
### Are there any user-facing changes?
Yes. `ListElementRef` can select an element per row from `list_view` and
`large_list_view` arrays. There is no API change.
---
arrow/compute/exprs/exec_test.go | 73 +++++++++++++++++++++++++++++++++------
arrow/compute/exprs/field_refs.go | 2 +-
2 files changed, 63 insertions(+), 12 deletions(-)
diff --git a/arrow/compute/exprs/exec_test.go b/arrow/compute/exprs/exec_test.go
index 2ecdfcd4..338e6c2b 100644
--- a/arrow/compute/exprs/exec_test.go
+++ b/arrow/compute/exprs/exec_test.go
@@ -1081,20 +1081,31 @@ func TestListElementRefPerRow(t *testing.T) {
slice [2]int64
offset int32
expected string
+ build func(memory.Allocator) arrow.Array
}{
- {"offset beyond the row count", arrow.ListOf(str), `[["a", "b",
"c"], ["d", "e", "f"]]`, [2]int64{}, 2, `["c", "f"]`},
- {"null row", arrow.ListOf(str), `[["a", "b"], null, ["e",
"f"]]`, [2]int64{}, 1, `["b", null, "f"]`},
- {"sliced", arrow.ListOf(str), `[["a", "b"], ["c", "d"], null,
["g", "h"]]`, [2]int64{1, 4}, 1, `["d", null, "h"]`},
- {"large list", arrow.LargeListOf(str), `[["a", "b"], ["c",
"d"]]`, [2]int64{}, 1, `["b", "d"]`},
- {"fixed size list", arrow.FixedSizeListOf(2, str), `[["a",
"b"], null, ["e", "f"]]`, [2]int64{}, 1, `["b", null, "f"]`},
+ {"offset beyond the row count", arrow.ListOf(str), `[["a", "b",
"c"], ["d", "e", "f"]]`, [2]int64{}, 2, `["c", "f"]`, nil},
+ {"null row", arrow.ListOf(str), `[["a", "b"], null, ["e",
"f"]]`, [2]int64{}, 1, `["b", null, "f"]`, nil},
+ {"sliced", arrow.ListOf(str), `[["a", "b"], ["c", "d"], null,
["g", "h"]]`, [2]int64{1, 4}, 1, `["d", null, "h"]`, nil},
+ {"large list", arrow.LargeListOf(str), `[["a", "b"], ["c",
"d"]]`, [2]int64{}, 1, `["b", "d"]`, nil},
+ {"fixed size list", arrow.FixedSizeListOf(2, str), `[["a",
"b"], null, ["e", "f"]]`, [2]int64{}, 1, `["b", null, "f"]`, nil},
+ {"list view out of order and overlapping", nil, "", [2]int64{},
1, `["e", "b", "c"]`, makeListView(false, []int32{3, 0, 1}, []int32{2, 3, 3},
nil)},
+ {"list view sliced", nil, "", [2]int64{1, 4}, 1, `["b", null,
"c"]`, makeListView(false, []int32{4, 0, 2, 1}, []int32{2, 2, 2, 3},
[]bool{true, true, false, true})},
+ {"large list view out of order and overlapping", nil, "",
[2]int64{}, 1, `["e", "b", "c"]`, makeListView(true, []int32{3, 0, 1},
[]int32{2, 3, 3}, nil)},
+ {"large list view sliced", nil, "", [2]int64{1, 4}, 1, `["b",
null, "c"]`, makeListView(true, []int32{4, 0, 2, 1}, []int32{2, 2, 2, 3},
[]bool{true, true, false, true})},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mem :=
memory.NewCheckedAllocator(memory.DefaultAllocator)
defer mem.AssertSize(t, 0)
- lists, _, err := array.FromJSON(mem, tt.dt,
strings.NewReader(tt.json))
- require.NoError(t, err)
+ var lists arrow.Array
+ if tt.build != nil {
+ lists = tt.build(mem)
+ } else {
+ var err error
+ lists, _, err = array.FromJSON(mem, tt.dt,
strings.NewReader(tt.json))
+ require.NoError(t, err)
+ }
if tt.slice != [2]int64{} {
sliced := array.NewSlice(lists, tt.slice[0],
tt.slice[1])
lists.Release()
@@ -1117,17 +1128,26 @@ func TestListElementRefPerRow(t *testing.T) {
name string
json string
offset int32
+ build func(memory.Allocator) arrow.Array
}{
- {"past the end of one row", `[["a", "b"], ["c"]]`, 1},
- {"negative offset", `[["a", "b"], ["c", "d"]]`, -1},
+ {"past the end of one row", `[["a", "b"], ["c"]]`, 1, nil},
+ {"negative offset", `[["a", "b"], ["c", "d"]]`, -1, nil},
+ {"past the end of one list view", "", 1, makeListView(false,
[]int32{3, 1}, []int32{3, 1}, nil)},
+ {"past the end of one large list view", "", 1,
makeListView(true, []int32{3, 1}, []int32{3, 1}, nil)},
}
for _, tt := range errTests {
t.Run("error "+tt.name, func(t *testing.T) {
mem :=
memory.NewCheckedAllocator(memory.DefaultAllocator)
defer mem.AssertSize(t, 0)
- lists, _, err := array.FromJSON(mem, arrow.ListOf(str),
strings.NewReader(tt.json))
- require.NoError(t, err)
+ var lists arrow.Array
+ if tt.build != nil {
+ lists = tt.build(mem)
+ } else {
+ var err error
+ lists, _, err = array.FromJSON(mem,
arrow.ListOf(str), strings.NewReader(tt.json))
+ require.NoError(t, err)
+ }
defer lists.Release()
result, err := exprs.GetReferencedValue(mem,
&expr.ListElementRef{Offset: tt.offset},
compute.NewDatumWithoutOwning(lists), extSet)
@@ -1187,6 +1207,37 @@ func TestListElementRefPerRow(t *testing.T) {
})
}
+// makeListView returns a function that builds a (large) list view whose rows
+// are the given views over the strings "a" to "f". A nil valid means all rows
+// are valid.
+func makeListView(large bool, offsets, sizes []int32, valid []bool)
func(memory.Allocator) arrow.Array {
+ return func(mem memory.Allocator) arrow.Array {
+ values := []string{"a", "b", "c", "d", "e", "f"}
+ if valid == nil {
+ valid = make([]bool, len(offsets))
+ for i := range valid {
+ valid[i] = true
+ }
+ }
+ if !large {
+ b := array.NewListViewBuilder(mem,
arrow.BinaryTypes.String)
+ defer b.Release()
+
b.ValueBuilder().(*array.StringBuilder).AppendValues(values, nil)
+ b.AppendValuesWithSizes(offsets, sizes, valid)
+ return b.NewArray()
+ }
+ b := array.NewLargeListViewBuilder(mem,
arrow.BinaryTypes.String)
+ defer b.Release()
+ b.ValueBuilder().(*array.StringBuilder).AppendValues(values,
nil)
+ offsets64, sizes64 := make([]int64, len(offsets)),
make([]int64, len(sizes))
+ for i := range offsets {
+ offsets64[i], sizes64[i] = int64(offsets[i]),
int64(sizes[i])
+ }
+ b.AppendValuesWithSizes(offsets64, sizes64, valid)
+ return b.NewArray()
+ }
+}
+
func TestNestedFieldRefSlicedStruct(t *testing.T) {
inner := arrow.StructOf(arrow.Field{Name: "a", Type:
arrow.PrimitiveTypes.Int32, Nullable: true})
sc := arrow.NewSchema([]arrow.Field{{Name: "s", Type: arrow.StructOf(
diff --git a/arrow/compute/exprs/field_refs.go
b/arrow/compute/exprs/field_refs.go
index b84873cb..b4235df4 100644
--- a/arrow/compute/exprs/field_refs.go
+++ b/arrow/compute/exprs/field_refs.go
@@ -278,7 +278,7 @@ func arrayStep(mem memory.Allocator, ref
expr.ReferenceSegment, v *compute.Array
return &compute.ArrayDatum{Value: field}, nil
case *expr.ListElementRef:
switch v.Type().ID() {
- case arrow.LIST, arrow.LARGE_LIST, arrow.FIXED_SIZE_LIST:
+ case arrow.LIST, arrow.LARGE_LIST, arrow.LIST_VIEW,
arrow.LARGE_LIST_VIEW, arrow.FIXED_SIZE_LIST:
default:
return nil, fmt.Errorf("%w: cannot reference list
element in non-list array type %s",
arrow.ErrInvalid, v.Type())