hcrosse opened a new issue, #1502:
URL: https://github.com/apache/arrow-go/issues/1502
### Describe the bug, including details regarding any error messages,
version, and platform.
Casting `bool`, `decimal128` or `decimal256` arrays to `int16` can return
wrong values without an error. Safe decimal casts also reject values that fit
in `int16` but not `int8` with `integer value out of bounds`.
I reproduced this on main at `32947b25` and on v18.8.0 with Go 1.26.10 on
macOS arm64. The incorrect kernel registration is also present in v18.0.0.
**Reproduction**
Save this as `main.go` in a new subdirectory of an arrow-go checkout at
`32947b259414a77ae6347d3d29bd69ec00b9d560`, then run `go run .` from that
directory:
```go
package main
import (
"context"
"fmt"
"strings"
"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/array"
"github.com/apache/arrow-go/v18/arrow/compute"
"github.com/apache/arrow-go/v18/arrow/memory"
)
func cast(dt arrow.DataType, values string) {
in, _, err := array.FromJSON(memory.DefaultAllocator, dt,
strings.NewReader(values))
if err != nil {
panic(err)
}
defer in.Release()
out, err := compute.CastArray(context.Background(), in,
compute.SafeCastOptions(arrow.PrimitiveTypes.Int16))
if out != nil {
defer out.Release()
}
fmt.Println(out, err)
}
func main() {
cast(arrow.FixedWidthTypes.Boolean, `[true, false, true, true]`)
cast(&arrow.Decimal128Type{Precision: 5, Scale: 0}, `["200", "-300"]`)
}
```
Actual output:
```text
[1 257 0 0] <nil>
<nil> invalid: integer value out of bounds
```
Expected output:
```text
[1 0 1 1] <nil>
[200 -300] <nil>
```
**Cause**
`cast_int16` uses `kernels.GetCastToInteger[int8]`. The boolean and decimal
kernels use that type parameter for writes and decimal bounds checks, so they
write `int8` values into an `int16` buffer and check against the `int8` range.
https://github.com/apache/arrow-go/blob/32947b259414a77ae6347d3d29bd69ec00b9d560/arrow/compute/cast.go#L844
I have a patch with tests and can open a PR.
### Component(s)
Other
--
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]