hcrosse commented on code in PR #1648:
URL: https://github.com/apache/arrow-go/pull/1648#discussion_r4645893455
##########
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:
`go.mod` targets Go 1.26 (`go 1.26`), so the predeclared `max` built-in is
always available.
##########
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:
`array.NewNull(math.MaxInt32)` allocates no data buffers (only an
`ArrayData` header), `math.MaxInt32` fits in a 32-bit `int`, and `AppendSlice`
returns `arrow.ErrInvalid` before reserving or appending children, so the test
runs in O(1) memory on both 32-bit and 64-bit.
##########
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:
`overInt32` must be a `var` so `int(overInt32)` compiles on `GOARCH=386`. A
`const` with value `math.MaxInt32 + 1` fails to compile as `int(overInt32)` on
32-bit even behind a runtime `strconv.IntSize == 32` skip.
--
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]