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

   ### Describe the bug
   
   Writing an empty slice of a nonempty `RunArray` to IPC succeeds, but the 
resulting batch cannot be read back. The writer emits a run end of `0`, which 
violates the requirement that run ends be strictly positive.
   
   ### To Reproduce
   
   ```rust
   use std::io::Cursor;
   use std::sync::Arc;
   
   use arrow_array::{ArrayRef, Int32Array, RecordBatch, RunArray, 
types::Int32Type};
   use arrow_ipc::{reader::StreamReader, writer::StreamWriter};
   
   let run_ends = Int32Array::from(vec![2, 5]);
   let values = Int32Array::from(vec![10, 20]);
   let array = RunArray::<Int32Type>::try_new(&run_ends, &values).unwrap();
   let empty = array.slice(2, 0);
   let batch = RecordBatch::try_from_iter(vec![("run", Arc::new(empty) as 
ArrayRef)]).unwrap();
   
   let mut writer = StreamWriter::try_new(Vec::new(), 
batch.schema_ref()).unwrap();
   writer.write(&batch).unwrap();
   writer.finish().unwrap();
   let bytes = writer.into_inner().unwrap();
   
   let mut reader = StreamReader::try_new(Cursor::new(bytes), None).unwrap();
   let decoded = reader.next().unwrap().unwrap(); // Panics
   assert_eq!(decoded, batch);
   ```
   
   The reader returns:
   
   ```text
   InvalidArgumentError("The values in run_ends array should be strictly 
positive. Found value 0 at index 0 that does not match the criteria.")
   ```
   
   ### Expected behavior
   
   Empty RunArray slices should roundtrip through Stream and File IPC 
successfully, with zero physical runs.
   
   ### Additional context
   
   Reproduced on commit `8c265f8de4e44a5fdda8aad79ccf890d53c6e601`. The same 
failure was reproduced with Int16, Int32, and Int64 run ends. This is an 
existing bug; its introducing commit has not been identified.
   
   In `into_zero_offset_run_array`, an empty slice has both physical indices 
equal to zero. The writer calculates a physical length of one and appends the 
logical length (`0`) as the final run end.
   
   Proposed fix and regression coverage: #11361.
   


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