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

Aperta
#12,425 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Subodh-17 ci sta già lavorando.

Dal 26/11/2026.

  • #12477 di @Subodh-17 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
data

Direzione di ricerca

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.

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

Descrizione

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.

Lingua principale
Rust
Stelle
3.7k
Fork
1.5k
Merge medio
2g 16h
PR unite (30g)
183

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

Tutte le issue di apache/arrow-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.