arrow/compute: safe float to integer cast skips the truncation check in sliced arrays with nulls
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 1/100
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
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/arrow-go
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
apache/arrow-go#1591 · 2 comments ·
Maintainers usually reply within 1 day
-
Type: bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
parquet/file: a panic recovered in WriteBatch is not kept, so Close writes a footer for rows with no valuesPossibly taken @EdwardShen125 claimed this 4 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
ipc: stream reader accepts an invalid flatbuffer schema and decimal precision 0Possibly taken @AynSiddiqui claimed this 7 days ago. Open
apache/arrow-go#1676 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
Battery "top up once" ends immediately when UPower reports fully-charged below 100%Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
omacom/omarchy#21286 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
-
Rejected regionUrl errors don't say how to recover when an agent passes the organization's web URLOpenmcp-feedback-pattern
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
getsentry/toolkit#2777 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
libsndfile/libsndfile#1239 ·