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 57e0c8d3 fix(arrow/compute): use int16 kernels for casts to int16 
(#1503)
57e0c8d3 is described below

commit 57e0c8d3209ee1d28d90c93ac2baeb531c5939c2
Author: Harrison Crosse <[email protected]>
AuthorDate: Tue Nov 10 14:24:34 2026 -0500

    fix(arrow/compute): use int16 kernels for casts to int16 (#1503)
    
    ### Rationale for this change
    
    Casting `bool`, `decimal128` and `decimal256` to `int16` can return
    wrong values or reject values that fit.
    
    ### What changes are included in this PR?
    
    `cast_int16` now uses `kernels.GetCastToInteger[int16]` instead of
    `kernels.GetCastToInteger[int8]`. The boolean and decimal kernels use
    this type parameter for writes and decimal bounds checks.
    
    ### Are these changes tested?
    
    `TestBooleanToNumber` checks boolean casts to the eight integer types,
    `float32` and `float64`, including nulls. The expanded
    `TestDecimal128ToInt` and `TestDecimal256ToInt` check `int16` values and
    bounds, which their existing cases missed.
    
    The new `int16` success cases fail on main and pass with this change.
    The bounds rejection cases pass on both. The issue's reproduction prints
    `[1 0 1 1]` and `[200 -300]` without errors with this change.
    
    `go test -tags assert,test ./arrow/...` with arrow-testing and
    parquet-testing checked out, `-race -tags assert,test` runs for compute
    and scalar, vet, lint and the Release Audit Tool passed with Go 1.26.10.
    
    ### Are there any user-facing changes?
    
    Yes. These casts return correct `int16` values and reject values outside
    its range with safe options. There is no API change.
    
    Closes https://github.com/apache/arrow-go/issues/1502.
---
 arrow/compute/cast.go      |  2 +-
 arrow/compute/cast_test.go | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/arrow/compute/cast.go b/arrow/compute/cast.go
index e1b504c0..ebf0f4fb 100644
--- a/arrow/compute/cast.go
+++ b/arrow/compute/cast.go
@@ -841,7 +841,7 @@ func getNumericCasts() []*castFunction {
        }
 
        out = append(out, getFn("cast_int8", arrow.INT8, 
kernels.GetCastToInteger[int8](arrow.PrimitiveTypes.Int8)))
-       out = append(out, getFn("cast_int16", arrow.INT16, 
kernels.GetCastToInteger[int8](arrow.PrimitiveTypes.Int16)))
+       out = append(out, getFn("cast_int16", arrow.INT16, 
kernels.GetCastToInteger[int16](arrow.PrimitiveTypes.Int16)))
 
        castInt32 := getFn("cast_int32", arrow.INT32, 
kernels.GetCastToInteger[int32](arrow.PrimitiveTypes.Int32))
        castInt32.AddTypeCast(arrow.DATE32,
diff --git a/arrow/compute/cast_test.go b/arrow/compute/cast_test.go
index fdcff6f1..9226cafd 100644
--- a/arrow/compute/cast_test.go
+++ b/arrow/compute/cast_test.go
@@ -880,6 +880,15 @@ func (c *CastSuite) TestDecimal128ToInt() {
                defer beyondBounds.Release()
                checkCastFails(c.T(), beyondBounds, *opts)
        })
+
+       c.Run("int16", func() {
+               opts := compute.SafeCastOptions(arrow.PrimitiveTypes.Int16)
+               dt := &arrow.Decimal128Type{Precision: 10, Scale: 0}
+
+               c.checkCastOpts(dt, arrow.PrimitiveTypes.Int16,
+                       `["200", "-300", "32767", "-32768", null]`, `[200, 
-300, 32767, -32768, null]`, *opts)
+               c.checkCastFails(dt, `["32768", "-32769"]`, opts)
+       })
 }
 
 func (c *CastSuite) TestDecimal256ToInt() {
@@ -1003,6 +1012,15 @@ func (c *CastSuite) TestDecimal256ToInt() {
                defer beyondBounds.Release()
                checkCastFails(c.T(), beyondBounds, *opts)
        })
+
+       c.Run("int16", func() {
+               opts := compute.SafeCastOptions(arrow.PrimitiveTypes.Int16)
+               dt := &arrow.Decimal256Type{Precision: 10, Scale: 0}
+
+               c.checkCastOpts(dt, arrow.PrimitiveTypes.Int16,
+                       `["200", "-300", "32767", "-32768", null]`, `[200, 
-300, 32767, -32768, null]`, *opts)
+               c.checkCastFails(dt, `["32768", "-32769"]`, opts)
+       })
 }
 
 func (c *CastSuite) TestIntegerToDecimal() {
@@ -3435,6 +3453,15 @@ func (c *CastSuite) TestBooleanToString() {
        }
 }
 
+func (c *CastSuite) TestBooleanToNumber() {
+       for _, dt := range numericTypes {
+               c.Run(dt.String(), func() {
+                       c.checkCast(arrow.FixedWidthTypes.Boolean, dt,
+                               `[true, false, null, true, true]`, `[1, 0, 
null, 1, 1]`)
+               })
+       }
+}
+
 func (c *CastSuite) TestIdentityCasts() {
        c.checkCastSelfZeroCopy(arrow.FixedWidthTypes.Boolean, `[false, true, 
null, false]`)
 

Reply via email to