Copilot commented on code in PR #1648:
URL: https://github.com/apache/arrow-go/pull/1648#discussion_r4645858319
##########
arrow/scalar/append.go:
##########
@@ -181,12 +182,30 @@ func appendToBldr(bldr array.Builder, scalars []Scalar)
error {
case *array.BinaryViewBuilder:
appendBinary(bldr, scalars)
case array.ListLikeBuilder:
- var numChildren int
+ limit := math.MaxInt
+ existingLen := bldr.ValueBuilder().Len()
+ switch b := bldr.(type) {
+ case *array.ListBuilder, *array.ListViewBuilder:
+ limit = math.MaxInt32
+ case *array.MapBuilder:
+ limit = math.MaxInt32
+ existingLen = max(existingLen, b.KeyBuilder().Len(),
b.ItemBuilder().Len())
+ }
Review Comment:
`max(...)` is the Go 1.21+ predeclared built-in. If this repo targets older
Go versions, this will fail to compile. Consider replacing it with a small
local helper (or simple comparisons) to compute the maximum of the three
lengths without relying on the newer built-in.
##########
arrow/scalar/append_overflow_test.go:
##########
@@ -0,0 +1,93 @@
+// 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 scalar_test
+
+import (
+ "math"
+ "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/arrow/scalar"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestAppendListOverflowReturnsInvalid(t *testing.T) {
+ mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+ defer mem.AssertSize(t, 0)
+
+ bigNull := array.NewNull(math.MaxInt32)
+ defer bigNull.Release()
Review Comment:
This test constructs an array with length `math.MaxInt32`. Even if `Null`
arrays are lightweight, running this on 32-bit platforms or in constrained CI
environments can be risky if any path allocates proportional to length.
Consider adding a `strconv.IntSize == 32` skip (like the array tests do) or
constructing a minimal `ArrayData`/scalar that exercises the overflow path
without requiring an apparent 2B-length array value.
##########
arrow/array/list_overflow_test.go:
##########
@@ -0,0 +1,154 @@
+// 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 array
+
+import (
+ "math"
+ "strconv"
+ "testing"
+
+ "github.com/apache/arrow-go/v18/arrow"
+ "github.com/apache/arrow-go/v18/arrow/memory"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+var overInt32 int64 = math.MaxInt32 + 1
Review Comment:
This can be a `const` instead of a `var` (it’s a pure compile-time value).
Making it a constant reduces the chance of accidental mutation and better
signals intent.
--
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]