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

Aperta
#1,712 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mansur-akhmadi ci sta già lavorando.

Dal 2/12/2026.

  • #1713 di @mansur-akhmadi — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
1/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Assembly
Stelle
423
Fork
188
Merge medio
1g 7h
PR unite (30g)
164

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/arrow-go

Tutte le issue di apache/arrow-go

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.