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

   ### Describe the bug
   
   After `PrimitiveRunBuilder::finish`, reusing the builder can go wrong:
   
   1. If the next batch is a single run (all values equal, or all null) with 
the same length as the previous batch, `finish` returns an empty array. The 
appended rows are silently lost.
   2. Calling `finish` again without appending anything panics. On a new 
builder, the same call returns an empty array.
   
   Other batch shapes are returned correctly. `StringRunBuilder` handles both 
sequences correctly.
   
   `finish` is documented as "Creates the RunArray and resets the builder", so 
the builder is expected to be reusable.
   
   ### To Reproduce
   
   With `arrow-array = "60.0.0"` (also reproduces on `main`):
   
   ```rust
   use arrow_array::Array;
   use arrow_array::builder::PrimitiveRunBuilder;
   use arrow_array::types::{Int16Type, Int32Type};
   
   fn main() {
       // A batch with the same length as the previous one, made of a single run
       let mut builder = PrimitiveRunBuilder::<Int16Type, Int32Type>::new();
       builder.extend([Some(1), Some(2), Some(3)]);
       println!("first batch:  len {}", builder.finish().len());
       builder.extend([Some(7), Some(7), Some(7)]);
       println!("second batch: len {}", builder.finish().len());
   
       // Calling finish again without appending anything
       let mut builder = PrimitiveRunBuilder::<Int16Type, Int32Type>::new();
       builder.extend([Some(1), Some(2), Some(3)]);
       builder.finish();
       builder.finish();
   }
   ```
   
   Output:
   
   ```
   first batch:  len 3
   second batch: len 0
   
   thread 'main' panicked at 
arrow-array-60.0.0/src/builder/primitive_run_builder.rs:210:64:
   called `Result::unwrap()` on an `Err` value: 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
   
   The second batch has length 3 (one run of `7`), and the last `finish` 
returns an empty array, as it does on a new builder.
   


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