This is an automated email from the ASF dual-hosted git repository.

Jefffrey pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new e6fb133e50 fix(arrow-array): reset NullBuilder length in finish 
(#11110)
e6fb133e50 is described below

commit e6fb133e506012e683f6f4207bfcf039a7221194
Author: ranflarion <[email protected]>
AuthorDate: Wed Sep 16 20:00:06 2026 -0400

    fix(arrow-array): reset NullBuilder length in finish (#11110)
    
    # Which issue does this PR close?
    
    - Closes #11109.
    
    # Rationale for this change
    
    `NullBuilder::finish` is documented to reset the builder but its body is
    the same as `finish_cloned`, so a builder reused across `finish` calls
    emits cumulative lengths. Every other builder resets on `finish`.
    
    # What changes are included in this PR?
    
    `finish` takes the length with `std::mem::take`, leaving the builder
    empty. `finish_cloned` is unchanged.
    
    # Are these changes tested?
    
    Yes. `test_null_array_builder_finish_resets` finishes twice and checks
    the builder is empty in between; it fails on `main` (`left: 0, right:
    10`) and passes with the change. `cargo test -p arrow-array`, `-p
    arrow-csv` and `-p parquet-variant-compute` pass; the two other in-tree
    callers of `NullBuilder::finish` each finish a fresh builder once, so
    their output does not change.
    
    # Are there any user-facing changes?
    
    `NullBuilder::finish` now resets the builder as documented. Code that
    relied on the previous non-resetting behavior would see shorter arrays
    from subsequent `finish` calls; that behavior contradicted the doc
    comment and every other builder. No API changes.
---
 arrow-array/src/builder/null_builder.rs | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/arrow-array/src/builder/null_builder.rs 
b/arrow-array/src/builder/null_builder.rs
index 9dab231b40..0f52be9ae9 100644
--- a/arrow-array/src/builder/null_builder.rs
+++ b/arrow-array/src/builder/null_builder.rs
@@ -85,7 +85,7 @@ impl NullBuilder {
 
     /// Builds the [NullArray] and reset this builder.
     pub fn finish(&mut self) -> NullArray {
-        let len = self.len();
+        let len = std::mem::take(&mut self.len);
         let builder = ArrayData::new_null(&DataType::Null, len).into_builder();
 
         // SAFETY: ArrayData::new_null produces valid null array data, so all 
builder invariants hold
@@ -169,4 +169,20 @@ mod tests {
         array = builder.finish();
         assert_eq!(10, array.len());
     }
+
+    #[test]
+    fn test_null_array_builder_finish_resets() {
+        let mut builder = NullBuilder::new();
+        builder.append_nulls(10);
+
+        let array = builder.finish();
+        assert_eq!(10, array.len());
+        assert_eq!(0, builder.len());
+        assert!(builder.is_empty());
+
+        builder.append_nulls(3);
+        let array = builder.finish();
+        assert_eq!(3, array.len());
+        assert_eq!(0, builder.len());
+    }
 }

Reply via email to