Skip to content

PrimitiveRunBuilder loses rows or panics when reused after finish #11325

Closed

Description

@neilconway

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

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.

Activity

  1. neilconway commented on Oct 1, 2026

    @neilconway
    ContributorAuthor

    take

  2. added a commit that references this issue on Oct 2, 2026
    a5ba6a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions