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 852d4a9bc2 Replace BufferBuilder with Vec in MapArrayDecoder (#10629)
852d4a9bc2 is described below

commit 852d4a9bc27a33e256b802cac46e828e5d1a9915
Author: cakeni <[email protected]>
AuthorDate: Thu Aug 20 09:23:34 2026 +0800

    Replace BufferBuilder with Vec in MapArrayDecoder (#10629)
    
    # Which issue does this PR close?
    
    - Part of #10245.
    
    # Rationale for this change
    
    Using `Vec` instead of `BufferBuilder` can improve performance by
    benefiting from Rust's optimized `Vec` implementation. This updates the
    remaining `BufferBuilder` usage in `arrow-json` and follows the existing
    `ListArrayDecoder` approach.
    
    # What changes are included in this PR?
    
    - Replace `MapArrayDecoder`'s offset `BufferBuilder<i32>` with a
    preallocated `Vec<i32>`.
    - Construct the final `ScalarBuffer` directly from the vector.
    - Remove the now-unused `BufferBuilder` import.
    
    # Are these changes tested?
    
    Yes. The following checks pass:
    
    - `cargo +stable-x86_64-pc-windows-gnu fmt --all -- --check`
    - `cargo +stable-x86_64-pc-windows-gnu clippy -p arrow-json
    --all-targets --all-features --no-deps -- -D warnings`
    - `cargo +stable-x86_64-pc-windows-gnu test -p arrow-json
    --all-features` (134 unit tests and 17 doctests passed)
    
    # Are there any user-facing changes?
    
    No.
    
    ## AI assistance
    
    OpenAI Codex assisted with code exploration and drafting this change. I
    reviewed the implementation and final diff.
    
    Co-authored-by: Jeffrey Vo <[email protected]>
---
 arrow-json/src/reader/map_array.rs | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arrow-json/src/reader/map_array.rs 
b/arrow-json/src/reader/map_array.rs
index abb035193c..cd8f868e31 100644
--- a/arrow-json/src/reader/map_array.rs
+++ b/arrow-json/src/reader/map_array.rs
@@ -17,7 +17,6 @@
 
 use std::sync::Arc;
 
-use arrow_array::builder::BufferBuilder;
 use arrow_array::{ArrayRef, MapArray, StructArray};
 use arrow_buffer::{ArrowNativeType, NullBufferBuilder, OffsetBuffer, 
ScalarBuffer};
 use arrow_schema::{ArrowError, DataType, FieldRef, Fields};
@@ -83,8 +82,8 @@ impl MapArrayDecoder {
 
 impl ArrayDecoder for MapArrayDecoder {
     fn decode(&mut self, tape: &Tape<'_>, pos: &[u32]) -> Result<ArrayRef, 
ArrowError> {
-        let mut offsets = BufferBuilder::<i32>::new(pos.len() + 1);
-        offsets.append(0);
+        let mut offsets = Vec::with_capacity(pos.len() + 1);
+        offsets.push(0);
 
         let mut key_pos = Vec::with_capacity(pos.len());
         let mut value_pos = Vec::with_capacity(pos.len());
@@ -122,7 +121,7 @@ impl ArrayDecoder for MapArrayDecoder {
             let offset = i32::from_usize(key_pos.len()).ok_or_else(|| {
                 ArrowError::JsonError("offset overflow decoding 
MapArray".to_string())
             })?;
-            offsets.append(offset)
+            offsets.push(offset)
         }
 
         assert_eq!(key_pos.len(), value_pos.len());
@@ -139,7 +138,7 @@ impl ArrayDecoder for MapArrayDecoder {
 
         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())) };
+        let offsets = unsafe { 
OffsetBuffer::new_unchecked(ScalarBuffer::from(offsets)) };
 
         let array = MapArray::try_new(
             self.entries_field.clone(),

Reply via email to