mbutrovich opened a new issue, #12425:
URL: https://github.com/apache/arrow-rs/issues/12425

   ### 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`](https://github.com/apache/arrow-rs/blob/6a3f719f1de43137f0ecc2e7de12d4a7a0b13bd5/arrow-select/src/take.rs#L519-L537)
 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`](https://github.com/apache/arrow-rs/blob/6a3f719f1de43137f0ecc2e7de12d4a7a0b13bd5/arrow-select/src/take.rs#L3436-L3451)
 checks that error.
   
   ### To Reproduce
   
   ```rust
   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`](https://github.com/apache/arrow-rs/blob/6a3f719f1de43137f0ecc2e7de12d4a7a0b13bd5/arrow-select/src/take.rs#L503-L514)
 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to