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

Abierto
#1,712 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@mansur-akhmadi ya está trabajando en esto.

Desde el 2/12/2026.

  • #1713 de @mansur-akhmadi — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
1/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
go
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Assembly
Estrellas
423
Forks
188
Merge medio
1 d 7 h
PR fusionados (30 d)
164

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/arrow-go

Todos los issues de apache/arrow-go

Issues similares

Más issues de Backend & API Design

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.