Copilot commented on code in PR #1595:
URL: https://github.com/apache/arrow-go/pull/1595#discussion_r4603488402


##########
arrow/compute/exprs/exec_test.go:
##########
@@ -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
+                       }
+               }

Review Comment:
   `makeListView` mutates the captured `valid` parameter when `valid == nil` by 
assigning a newly-created slice to it. Because `valid` is closed over, any 
subsequent invocation of the returned builder function will reuse that slice, 
which is a surprising side-effect for a helper that looks like it should be 
pure. Prefer using a new local variable (e.g., `rowValid := valid`) inside the 
closure and only initialize that local when nil, so each call behaves 
deterministically and doesn’t mutate captured inputs.



##########
arrow/compute/exprs/exec_test.go:
##########
@@ -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])
+               }

Review Comment:
   This loop ranges over `offsets` but indexes `sizes[i]`. If `len(sizes) < 
len(offsets)`, this will panic with an out-of-range access. Even though current 
call sites pass matching lengths, it’s easy for a future test to violate this 
and produce a non-obvious panic. Add an explicit length check at the start of 
the builder (offsets vs sizes, and also `valid` length when non-nil) and fail 
fast with a clear message.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to