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

alamb 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 c4b2569276 Replace `BooleanBufferBuilder` with `NullBufferBuilder` in 
arrow-json if applicable (#9811)
c4b2569276 is described below

commit c4b2569276b5da0a57a18abaf3de6e1b04676c1b
Author: Liam Bao <[email protected]>
AuthorDate: Sat Apr 25 11:23:31 2026 -0400

    Replace `BooleanBufferBuilder` with `NullBufferBuilder` in arrow-json if 
applicable (#9811)
    
    # Which issue does this PR close?
    
    <!--
    We generally require a GitHub issue to be filed for all bug fixes and
    enhancements and this helps us generate change logs for our releases.
    You can link an issue to this PR using the GitHub syntax.
    -->
    
    - Closes #9781.
    
    # Rationale for this change
    
    <!--
    Why are you proposing this change? If this is already explained clearly
    in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand
    your changes and offer better suggestions for fixes.
    -->
    
    # What changes are included in this PR?
    
    <!--
    There is no need to duplicate the description in the issue here but it
    is sometimes worth providing a summary of the individual changes in this
    PR.
    -->
    
    Replace `BooleanBufferBuilder` with `NullBufferBuilder` so we get the
    benefit of late materialization
    
    # Are these changes tested?
    
    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    If tests are not included in your PR, please explain why (for example,
    are they covered by existing tests)?
    -->
    
    Covered by existing tests
    
    # Are there any user-facing changes?
    
    <!--
    If there are user-facing changes then we may require documentation to be
    updated before approving the PR.
    
    If there are any breaking changes to public APIs, please call them out.
    -->
    No
---
 arrow-json/src/reader/list_array.rs   | 28 +++++++++++-----------------
 arrow-json/src/reader/map_array.rs    | 17 +++++++----------
 arrow-json/src/reader/struct_array.rs | 21 +++++++++------------
 3 files changed, 27 insertions(+), 39 deletions(-)

diff --git a/arrow-json/src/reader/list_array.rs 
b/arrow-json/src/reader/list_array.rs
index ac574fab16..778b2e2804 100644
--- a/arrow-json/src/reader/list_array.rs
+++ b/arrow-json/src/reader/list_array.rs
@@ -18,12 +18,10 @@
 use std::marker::PhantomData;
 use std::sync::Arc;
 
-use arrow_array::builder::BooleanBufferBuilder;
 use arrow_array::{
     ArrayRef, FixedSizeListArray, GenericListArray, GenericListViewArray, 
OffsetSizeTrait,
 };
-use arrow_buffer::buffer::NullBuffer;
-use arrow_buffer::{OffsetBuffer, ScalarBuffer};
+use arrow_buffer::{NullBufferBuilder, OffsetBuffer, ScalarBuffer};
 use arrow_schema::{ArrowError, DataType, FieldRef};
 
 use crate::reader::tape::{Tape, TapeElement};
@@ -71,23 +69,21 @@ impl<O: OffsetSizeTrait, const IS_VIEW: bool> ArrayDecoder 
for ListLikeArrayDeco
         let mut offsets = Vec::with_capacity(pos.len() + 1);
         offsets.push(O::from_usize(0).unwrap());
 
-        let mut nulls = self
-            .is_nullable
-            .then(|| BooleanBufferBuilder::new(pos.len()));
+        let mut nulls = self.is_nullable.then(|| 
NullBufferBuilder::new(pos.len()));
 
         for p in pos {
             let end_idx = match (tape.get(*p), nulls.as_mut()) {
                 (TapeElement::StartList(end_idx), None) => end_idx,
                 (TapeElement::StartList(end_idx), Some(nulls)) => {
-                    nulls.append(true);
+                    nulls.append_non_null();
                     end_idx
                 }
                 (TapeElement::Null, Some(nulls)) => {
-                    nulls.append(false);
+                    nulls.append_null();
                     *p + 1
                 }
                 (_, Some(nulls)) if self.ignore_type_conflicts => {
-                    nulls.append(false);
+                    nulls.append_null();
                     *p + 1
                 }
                 _ => return Err(tape.error(*p, "[")),
@@ -108,7 +104,7 @@ impl<O: OffsetSizeTrait, const IS_VIEW: bool> ArrayDecoder 
for ListLikeArrayDeco
         }
 
         let values = self.decoder.decode(tape, &child_pos)?;
-        let nulls = nulls.as_mut().map(|x| NullBuffer::new(x.finish()));
+        let nulls = nulls.as_mut().and_then(|x| x.finish());
 
         if IS_VIEW {
             let mut sizes = Vec::with_capacity(offsets.len() - 1);
@@ -172,24 +168,22 @@ impl ArrayDecoder for FixedSizeListArrayDecoder {
         let expected = self.size as usize;
         let mut child_pos = Vec::with_capacity(pos.len() * expected);
 
-        let mut nulls = self
-            .is_nullable
-            .then(|| BooleanBufferBuilder::new(pos.len()));
+        let mut nulls = self.is_nullable.then(|| 
NullBufferBuilder::new(pos.len()));
 
         for p in pos {
             let end_idx = match (tape.get(*p), nulls.as_mut()) {
                 (TapeElement::StartList(end_idx), None) => end_idx,
                 (TapeElement::StartList(end_idx), Some(nulls)) => {
-                    nulls.append(true);
+                    nulls.append_non_null();
                     end_idx
                 }
                 (TapeElement::Null, Some(nulls)) => {
-                    nulls.append(false);
+                    nulls.append_null();
                     child_pos.resize(child_pos.len() + expected, 0);
                     continue;
                 }
                 (_, Some(nulls)) if self.ignore_type_conflicts => {
-                    nulls.append(false);
+                    nulls.append_null();
                     child_pos.resize(child_pos.len() + expected, 0);
                     continue;
                 }
@@ -213,7 +207,7 @@ impl ArrayDecoder for FixedSizeListArrayDecoder {
         }
 
         let values = self.decoder.decode(tape, &child_pos)?;
-        let nulls = nulls.as_mut().map(|x| NullBuffer::new(x.finish()));
+        let nulls = nulls.as_mut().and_then(|x| x.finish());
 
         let array = FixedSizeListArray::try_new(self.field.clone(), self.size, 
values, nulls)?;
         Ok(Arc::new(array))
diff --git a/arrow-json/src/reader/map_array.rs 
b/arrow-json/src/reader/map_array.rs
index 87cd84cc3e..396b60b162 100644
--- a/arrow-json/src/reader/map_array.rs
+++ b/arrow-json/src/reader/map_array.rs
@@ -17,10 +17,9 @@
 
 use std::sync::Arc;
 
-use arrow_array::builder::{BooleanBufferBuilder, BufferBuilder};
+use arrow_array::builder::BufferBuilder;
 use arrow_array::{ArrayRef, MapArray, StructArray};
-use arrow_buffer::buffer::NullBuffer;
-use arrow_buffer::{ArrowNativeType, OffsetBuffer, ScalarBuffer};
+use arrow_buffer::{ArrowNativeType, NullBufferBuilder, OffsetBuffer, 
ScalarBuffer};
 use arrow_schema::{ArrowError, DataType, FieldRef, Fields};
 
 use crate::reader::tape::{Tape, TapeElement};
@@ -90,23 +89,21 @@ impl ArrayDecoder for MapArrayDecoder {
         let mut key_pos = Vec::with_capacity(pos.len());
         let mut value_pos = Vec::with_capacity(pos.len());
 
-        let mut nulls = self
-            .is_nullable
-            .then(|| BooleanBufferBuilder::new(pos.len()));
+        let mut nulls = self.is_nullable.then(|| 
NullBufferBuilder::new(pos.len()));
 
         for p in pos.iter().copied() {
             let end_idx = match (tape.get(p), nulls.as_mut()) {
                 (TapeElement::StartObject(end_idx), None) => end_idx,
                 (TapeElement::StartObject(end_idx), Some(nulls)) => {
-                    nulls.append(true);
+                    nulls.append_non_null();
                     end_idx
                 }
                 (TapeElement::Null, Some(nulls)) => {
-                    nulls.append(false);
+                    nulls.append_null();
                     p + 1
                 }
                 (_, Some(nulls)) if self.ignore_type_conflicts => {
-                    nulls.append(false);
+                    nulls.append_null();
                     p + 1
                 }
                 _ => return Err(tape.error(p, "{")),
@@ -143,7 +140,7 @@ impl ArrayDecoder for MapArrayDecoder {
             )
         };
 
-        let nulls = nulls.as_mut().map(|x| NullBuffer::new(x.finish()));
+        let nulls = nulls.as_mut().and_then(|x| x.finish());
         // SAFETY: offsets are built monotonically starting from 0
         let offsets = unsafe { 
OffsetBuffer::new_unchecked(ScalarBuffer::from(offsets.finish())) };
 
diff --git a/arrow-json/src/reader/struct_array.rs 
b/arrow-json/src/reader/struct_array.rs
index cfad1ed612..d310618e10 100644
--- a/arrow-json/src/reader/struct_array.rs
+++ b/arrow-json/src/reader/struct_array.rs
@@ -18,9 +18,8 @@
 use std::collections::HashMap;
 use std::sync::Arc;
 
-use arrow_array::builder::BooleanBufferBuilder;
 use arrow_array::{Array, ArrayRef, StructArray};
-use arrow_buffer::buffer::NullBuffer;
+use arrow_buffer::NullBufferBuilder;
 use arrow_schema::{ArrowError, DataType, Fields};
 
 use crate::reader::tape::{Tape, TapeElement};
@@ -126,9 +125,7 @@ impl ArrayDecoder for StructArrayDecoder {
         let row_count = pos.len();
         let field_count = fields.len();
         self.field_tape_positions.resize(field_count, row_count)?;
-        let mut nulls = self
-            .is_nullable
-            .then(|| BooleanBufferBuilder::new(pos.len()));
+        let mut nulls = self.is_nullable.then(|| 
NullBufferBuilder::new(pos.len()));
 
         {
             // We avoid having the match on self.struct_mode inside the hot 
loop for performance
@@ -139,15 +136,15 @@ impl ArrayDecoder for StructArrayDecoder {
                         let end_idx = match (tape.get(*p), nulls.as_mut()) {
                             (TapeElement::StartObject(end_idx), None) => 
end_idx,
                             (TapeElement::StartObject(end_idx), Some(nulls)) 
=> {
-                                nulls.append(true);
+                                nulls.append_non_null();
                                 end_idx
                             }
                             (TapeElement::Null, Some(nulls)) => {
-                                nulls.append(false);
+                                nulls.append_null();
                                 continue;
                             }
                             (_, Some(nulls)) if self.ignore_type_conflicts => {
-                                nulls.append(false);
+                                nulls.append_null();
                                 continue;
                             }
                             (_, _) => return Err(tape.error(*p, "{")),
@@ -188,15 +185,15 @@ impl ArrayDecoder for StructArrayDecoder {
                         let end_idx = match (tape.get(*p), nulls.as_mut()) {
                             (TapeElement::StartList(end_idx), None) => end_idx,
                             (TapeElement::StartList(end_idx), Some(nulls)) => {
-                                nulls.append(true);
+                                nulls.append_non_null();
                                 end_idx
                             }
                             (TapeElement::Null, Some(nulls)) => {
-                                nulls.append(false);
+                                nulls.append_null();
                                 continue;
                             }
                             (_, Some(nulls)) if self.ignore_type_conflicts => {
-                                nulls.append(false);
+                                nulls.append_null();
                                 continue;
                             }
                             (_, _) => return Err(tape.error(*p, "[")),
@@ -245,7 +242,7 @@ impl ArrayDecoder for StructArrayDecoder {
             })
             .collect::<Result<Vec<_>, ArrowError>>()?;
 
-        let nulls = nulls.as_mut().map(|x| NullBuffer::new(x.finish()));
+        let nulls = nulls.as_mut().and_then(|x| x.finish());
 
         for (c, f) in child_arrays.iter().zip(fields) {
             // Sanity check

Reply via email to