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 2f3cd82bea fix: Avoid dropping type parameters in 
`PrimitiveArray::into_builder` (#11310)
2f3cd82bea is described below

commit 2f3cd82bea9f5baabdcc5b76efb4624620eeeb15
Author: Neil Conway <[email protected]>
AuthorDate: Wed Sep 30 22:46:11 2026 -0400

    fix: Avoid dropping type parameters in `PrimitiveArray::into_builder` 
(#11310)
    
    # Which issue does this PR close?
    
    - N/A
    
    # Rationale for this change
    
    If `PrimitiveArray::into_builder` fails to convert the array into the
    builder, we are supposed to return the input array unchanged. The
    previous implementation rebuilt the array with `T::DATA_TYPE`, which
    doesn't preserve type parameters (like the scale/precision of a decimal,
    or the timezone of a timestamp).
    
    # What changes are included in this PR?
    
    * Fix bug
    * Add unit test
    
    # Are these changes tested?
    
    Yes; existing tests pass, new test added.
    
    # Are there any user-facing changes?
    
    No.
---
 arrow-array/src/array/primitive_array.rs | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/arrow-array/src/array/primitive_array.rs 
b/arrow-array/src/array/primitive_array.rs
index 30d8f95f80..ae1b727745 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -1150,6 +1150,7 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
     /// `Err(self)`
     pub fn into_builder(self) -> Result<PrimitiveBuilder<T>, Self> {
         let len = self.len();
+        let data_type = self.data_type.clone();
         let data = self.into_data();
         let null_bit_buffer = data.nulls().map(|b| b.inner().sliced());
 
@@ -1191,7 +1192,7 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
         match try_mutable_buffers {
             Ok(builder) => Ok(builder),
             Err((buffer, null_bit_buffer)) => {
-                let builder = ArrayData::builder(T::DATA_TYPE)
+                let builder = ArrayData::builder(data_type)
                     .len(len)
                     .add_buffer(buffer)
                     .null_bit_buffer(null_bit_buffer);
@@ -2935,6 +2936,17 @@ mod tests {
         }
     }
 
+    #[test]
+    fn test_into_builder_err_keeps_data_type() {
+        let array = Decimal128Array::from(vec![1, 2])
+            .with_precision_and_scale(10, 2)
+            .unwrap();
+        let shared = array.clone();
+
+        let err_return = array.into_builder().unwrap_err();
+        assert_eq!(err_return.data_type(), shared.data_type());
+    }
+
     #[test]
     fn test_into_builder_on_sliced_array() {
         let array: Int32Array = vec![1, 2, 3].into_iter().map(Some).collect();

Reply via email to