`take` rejects a null index into an empty struct or fixed-size list whose child cannot hold a null

Abierto
#12,425 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Subodh-17 ya está trabajando en esto.

Desde el 26/11/2026.

  • #12477 de @Subodh-17 — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
data

Línea de trabajo

Start in arrow-select/src/take.rs: take_masked_child (around lines 519-537) hands an empty child to take_impl with null indices intact, and test_take_null_indices_masked_by_parent (around lines 3436-3451) currently asserts the error. Compare it with take_sparse_union_child (around lines 503-514), which builds a null array and drops its null buffer for the same empty case. Run the reproducer from the issue, then the arrow-select take tests; done means the three failing calls return Ok(1) and the empty union-with-no-fields error still stands.

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

Descripción

Describe the bug

#12365 fixed #11608 for a non-empty parent. A null index into a struct or fixed-size list of length 0 still fails when a child is run-end encoded with a non-nullable values field, or is a union with no nullable field. A parent sliced to length 0 fails the same way. take of a null index from an empty Int32Array returns one null row, and the parent's validity can hold that null here too.

take_masked_child passes an empty child to take_impl with the null indices unchanged, because it has no value to use as a dummy. test_take_null_indices_masked_by_parent checks that error.

To Reproduce
use std::sync::Arc;

use arrow_array::types::Int32Type;
use arrow_array::{make_array, Array, ArrayRef, FixedSizeListArray, Int32Array, PrimitiveArray, StructArray};
use arrow_buffer::NullBuffer;
use arrow_data::ArrayDataBuilder;
use arrow_schema::{DataType, Field, Fields};
use arrow_select::take::take;

fn main() {
    let ree_type = DataType::RunEndEncoded(
        Arc::new(Field::new("run_ends", DataType::Int32, false)),
        Arc::new(Field::new("values", DataType::Int32, false)),
    );
    let ree = |run_ends: Vec<i32>, values: Vec<i32>| -> ArrayRef {
        let len = run_ends.last().copied().unwrap_or(0) as usize;
        make_array(
            ArrayDataBuilder::new(ree_type.clone())
                .len(len)
                .add_child_data(Int32Array::from(run_ends).into_data())
                .add_child_data(Int32Array::from(values).into_data())
                .build()
                .unwrap(),
        )
    };
    let strukt = |child: ArrayRef| -> ArrayRef {
        let n = child.len();
        Arc::new(StructArray::new(Fields::from(vec![Field::new("c", ree_type.clone(), true)]), vec![child], Some(NullBuffer::new_valid(n))))
    };
    let null = PrimitiveArray::<Int32Type>::from(vec![None]);

    println!("{:?}", take(&strukt(ree(vec![1, 2], vec![10, 20])), &PrimitiveArray::<Int32Type>::from(vec![Some(1), None]), None).map(|a| a.null_count()));
    // Ok(1)
    println!("{:?}", take(&strukt(ree(vec![], vec![])), &null, None).map(|a| a.null_count()));
    // Err(ComputeError("Cannot take null indices from a RunEndEncoded array with a non-nullable values field"))
    println!("{:?}", take(&strukt(ree(vec![1, 2], vec![10, 20])).slice(1, 0), &null, None).map(|a| a.null_count()));
    // Err(ComputeError("Cannot take null indices from a RunEndEncoded array with a non-nullable values field"))
    let fsl = FixedSizeListArray::new(Arc::new(Field::new("item", ree_type.clone(), true)), 1, ree(vec![], vec![]), Some(NullBuffer::new_valid(0)));
    println!("{:?}", take(&fsl, &null, None).map(|a| a.null_count()));
    // Err(ComputeError("Cannot take null indices from a RunEndEncoded array with a non-nullable values field"))
    println!("{:?}", take(&Int32Array::from(Vec::<i32>::new()), &null, None).map(|a| a.null_count()));
    // Ok(1)
}

A struct of length 0 over a union with one non-nullable Int32 field fails the same way, with "Cannot take null indices from a union with no field that can represent nulls".

Expected behavior

Ok(1) for the three failing calls: one null row, held in the parent's validity.

Additional context

Could take_masked_child build an empty child's result the way take_sparse_union_child does for the same case, with new_null_array and its null buffer removed? A union with no fields has no value of any kind, so the error would stay for that case only.

Found with property-based tests that build arrays in every physical layout the Arrow format allows, on main at 6a3f719f. The take, take_record_batch, coalesce, and take-composition properties all reach it, usually through an empty or zero-length sliced struct.

Lenguaje dominante
Rust
Estrellas
3.7k
Forks
1.5k
Merge medio
2 d 16 h
PR fusionados (30 d)
183

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-rs

Todos los issues de apache/arrow-rs

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.