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 38d78c3e71 Support `GenericListViewArray::new_unchecked` and refactor 
`ListView` json decoder (#9648)
38d78c3e71 is described below

commit 38d78c3e7153e04a219aea39964ee00222c5e4f2
Author: Liam Bao <[email protected]>
AuthorDate: Wed Apr 15 11:36:54 2026 -0400

    Support `GenericListViewArray::new_unchecked` and refactor `ListView` json 
decoder (#9648)
    
    # 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 #9646.
    
    # 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.
    -->
    
    Support `GenericListViewArray::new_unchecked` and refactor ListView json
    decoder. Stacked on #9497, benchmark added in #9647
    
    # 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-array/src/array/list_view_array.rs | 29 +++++++++++++++++++++++++++++
 arrow-json/src/reader/list_array.rs      | 28 +++++++++++-----------------
 2 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/arrow-array/src/array/list_view_array.rs 
b/arrow-array/src/array/list_view_array.rs
index 75ff6117ee..a032d8715a 100644
--- a/arrow-array/src/array/list_view_array.rs
+++ b/arrow-array/src/array/list_view_array.rs
@@ -223,6 +223,35 @@ impl<OffsetSize: OffsetSizeTrait> 
GenericListViewArray<OffsetSize> {
         Self::try_new(field, offsets, sizes, values, nulls).unwrap()
     }
 
+    /// Create a new [`GenericListViewArray`] from the provided parts without 
validation
+    ///
+    /// See [`Self::try_new`] for the checked version of this function, and the
+    /// documentation of that function for the invariants that must be upheld.
+    ///
+    /// # Safety
+    ///
+    /// The parts must form a valid [`ListViewArray`] or 
[`LargeListViewArray`] according
+    /// to the Arrow spec.
+    pub unsafe fn new_unchecked(
+        field: FieldRef,
+        offsets: ScalarBuffer<OffsetSize>,
+        sizes: ScalarBuffer<OffsetSize>,
+        values: ArrayRef,
+        nulls: Option<NullBuffer>,
+    ) -> Self {
+        if cfg!(feature = "force_validate") {
+            return Self::new(field, offsets, sizes, values, nulls);
+        }
+
+        Self {
+            data_type: Self::DATA_TYPE_CONSTRUCTOR(field),
+            nulls,
+            values,
+            value_offsets: offsets,
+            value_sizes: sizes,
+        }
+    }
+
     /// Create a new [`GenericListViewArray`] of length `len` where all values 
are null
     pub fn new_null(field: FieldRef, len: usize) -> Self {
         let values = new_empty_array(field.data_type());
diff --git a/arrow-json/src/reader/list_array.rs 
b/arrow-json/src/reader/list_array.rs
index 113e628541..9f9758b84f 100644
--- a/arrow-json/src/reader/list_array.rs
+++ b/arrow-json/src/reader/list_array.rs
@@ -19,10 +19,9 @@ use std::marker::PhantomData;
 use std::sync::Arc;
 
 use arrow_array::builder::BooleanBufferBuilder;
-use arrow_array::{ArrayRef, GenericListArray, OffsetSizeTrait, make_array};
+use arrow_array::{ArrayRef, GenericListArray, GenericListViewArray, 
OffsetSizeTrait};
 use arrow_buffer::buffer::NullBuffer;
-use arrow_buffer::{Buffer, OffsetBuffer, ScalarBuffer};
-use arrow_data::ArrayDataBuilder;
+use arrow_buffer::{OffsetBuffer, ScalarBuffer};
 use arrow_schema::{ArrowError, DataType, FieldRef};
 
 use crate::reader::tape::{Tape, TapeElement};
@@ -115,22 +114,17 @@ impl<O: OffsetSizeTrait, const IS_VIEW: bool> 
ArrayDecoder for ListLikeArrayDeco
                 sizes.push(offsets[i] - offsets[i - 1]);
             }
             offsets.pop();
-            let data_type = if O::IS_LARGE {
-                DataType::LargeListView(self.field.clone())
-            } else {
-                DataType::ListView(self.field.clone())
-            };
             // SAFETY: offsets and sizes are constructed correctly from the 
tape
-            let array_data = unsafe {
-                ArrayDataBuilder::new(data_type)
-                    .len(pos.len())
-                    .nulls(nulls)
-                    .child_data(vec![values.to_data()])
-                    .add_buffer(Buffer::from_vec(offsets))
-                    .add_buffer(Buffer::from_vec(sizes))
-                    .build_unchecked()
+            let array = unsafe {
+                GenericListViewArray::<O>::new_unchecked(
+                    self.field.clone(),
+                    ScalarBuffer::from(offsets),
+                    ScalarBuffer::from(sizes),
+                    values,
+                    nulls,
+                )
             };
-            Ok(make_array(array_data))
+            Ok(Arc::new(array))
         } else {
             // SAFETY: offsets are built monotonically starting from 0
             let offsets = unsafe { 
OffsetBuffer::<O>::new_unchecked(ScalarBuffer::from(offsets)) };

Reply via email to