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

   ### Describe the bug
   
   `StructArray::flatten` puts the struct's validity into every child with 
`build_unchecked`, whatever the child's type. A `Null` child panics, and 
run-end encoded and union children have no validity bitmap, so the struct's 
null row is silently lost. `RecordBatch::normalize` goes through `flatten`, so 
it has the same problem.
   
   ### To Reproduce
   
   arrow 60.2.0, same code on main.
   
   ```rust
   use std::sync::Arc;
   use arrow::array::*;
   use arrow::buffer::NullBuffer;
   use arrow::datatypes::*;
   
   let nulls = Some(NullBuffer::from(vec![true, false, true]));
   
   // the null row is lost, logical null count 0 and values [10, 10, 20]
   let ree = RunArray::<Int32Type>::try_new(
       &Int32Array::from(vec![2, 3]),
       &Int64Array::from(vec![10, 20]),
   )
   .unwrap();
   let st = StructArray::new(
       Fields::from(vec![Field::new("r", ree.data_type().clone(), true)]),
       vec![Arc::new(ree) as ArrayRef],
       nulls.clone(),
   );
   let (_, columns) = st.flatten();
   assert_eq!(columns[0].logical_null_count(), 0);
   
   // panics: "NullArray data should not contain a null buffer, as no buffers 
are required"
   let st = StructArray::new(
       Fields::from(vec![Field::new("n", DataType::Null, true)]),
       vec![Arc::new(NullArray::new(3)) as ArrayRef],
       nulls,
   );
   let _ = st.flatten();
   ```
   
   A sparse union child behaves like the run-end encoded one.
   
   ### Expected behavior
   
   A `Null` child comes back unchanged, since every value is already null. A 
run-end encoded or union child either gets the null row or `flatten` returns an 
error. It should not panic or drop the null.
   
   ### Additional context
   
   We hit this profiling struct arrays with null rows in dataprof and wrote our 
own masking around it. Ours decodes a run-end encoded child, masks it and 
encodes it again, and refuses a union child.
   
   ### Willingness to contribute
   
   I would like to contribute a fix for this bug, but request guidance from the 
community
   


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