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

   ### Describe the bug
   
   `interleave_record_batch` reads the schema from `record_batches[0]` 
([interleave.rs](https://github.com/apache/arrow-rs/blob/01a9917658fecd639991e92a5a5810be710b539c/arrow-select/src/interleave.rs#L972)),
 so it panics on no batches, where `interleave` returns an error. It builds the 
result with `RecordBatch::try_new` 
([interleave.rs](https://github.com/apache/arrow-rs/blob/01a9917658fecd639991e92a5a5810be710b539c/arrow-select/src/interleave.rs#L982)),
 which needs a row count when there are no columns.
   
   ### To Reproduce
   
   ```rust
   use std::panic::catch_unwind;
   use std::sync::Arc;
   
   use arrow_array::{Int32Array, RecordBatch, RecordBatchOptions};
   use arrow_schema::Schema;
   use arrow_select::interleave::interleave_record_batch;
   use arrow_select::take::take_record_batch;
   
   fn main() {
       // A batch with no columns and 3 rows
       let options = RecordBatchOptions::new().with_row_count(Some(3));
       let none = RecordBatch::try_new_with_options(Arc::new(Schema::empty()), 
vec![], &options).unwrap();
       println!("{:?}", interleave_record_batch(&[&none], &[(0, 0), (0, 2)]));
       // Err(InvalidArgumentError("must either specify a row count or at least 
one column"))
       println!("{:?}", take_record_batch(&none, &Int32Array::from(vec![0, 
2])).map(|b| b.num_rows()));
       // Ok(2)
   
       let r = catch_unwind(|| interleave_record_batch(&[], &[]).map(|_| ()));
       println!("{}", r.is_err());
       // true: panics with "index out of bounds: the len is 0 but the index is 
0"
   }
   ```
   
   ### Expected behavior
   
   An error for no batches. For batches with no columns, a batch of 
`indices.len()` rows, as `take_record_batch` returns.
   
   Found with property-based tests that build arrays in every physical layout 
the Arrow format allows, on `main` at `01a991765`.
   


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