arrow/compute: safe float to integer cast skips the truncation check in sliced arrays with nulls

Open
#1,712 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@mansur-akhmadi is already working on this.

Since Dec 2, 2026.

  • #1713 by @mansur-akhmadi — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
1/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
go
Domain
backend

Research direction

Read arrow/compute/internal/kernels/numeric_cast.go, especially checkFloatTrunc, and compare its bitmap lookup with the offset handling in helpers.go. The issue includes sliced-array examples that reproduce both incorrect outcomes; use them to check the behavior. Done means safe casts report truncation for fractional valid values and ignore values stored under nulls. A linked pull request is already open.

Written by the indexing model from the issue text.

Description

Describe the bug, including details regarding any error messages, version, and platform.

A safe cast (compute.SafeCastOptions) from a float array to an integer type reads the validity bitmap at the wrong position when the input is a slice and a block contains nulls. A fractional value can be truncated without an error:

bldr := array.NewFloat64Builder(memory.DefaultAllocator)
bldr.AppendValues([]float64{0, 1.5, 2, 0}, []bool{false, true, true, false})
arr := bldr.NewArray()
s := array.NewSlice(arr, 1, 4) // [1.5 2 (null)]
out, err := compute.CastArray(context.Background(), s, compute.SafeCastOptions(arrow.PrimitiveTypes.Int32))
fmt.Println(out, err) // [1 2 (null)] <nil>

Expected: float value 1.500000 was truncated converting to int32, which is what the same values give unsliced.

It also fails the other way. If a null slot inside the slice stores a fractional value ([0, 1.5, 2, 9.5, 7.5] with index 0 and 3 null, sliced [2:4] = [2 (null)]), the cast fails because it checks the 9.5 under the null.

Cause: checkFloatTrunc in arrow/compute/internal/kernels/numeric_cast.go starts offsetPos at 0, then calls bitutil.BitIsSet(bitmap, int(offsetPos)+i). The block counter and the value slices already account for in.Offset, so the bitmap lookup is shifted by the slice offset. The integer bounds check in helpers.go starts at data.Offset.

main at e96596d, Go 1.26.4, darwin/arm64. The code path doesn't depend on the platform.

I have a fix with a test and will open a PR.

Component(s)

Other

Dominant language
Assembly
Stars
423
Forks
188
Avg merge
1d 7h
Merged PRs (30d)
164

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/arrow-go

All issues in apache/arrow-go

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.