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

github-merge-queue[bot] 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 f358c6d4f6 fix(arrow-array): keep precision and scale in 
null_if_overflow_precision (#12242)
f358c6d4f6 is described below

commit f358c6d4f638e8786f3404e061f55177a1ba26f6
Author: dayan02dev <[email protected]>
AuthorDate: Sat Nov 14 05:46:10 2026 +0000

    fix(arrow-array): keep precision and scale in null_if_overflow_precision 
(#12242)
    
    # Which issue does this PR close?
    
    - Closes #11300
    
    # Rationale for this change
    
    `null_if_overflow_precision` returned the default type of the decimal
    width instead of the input's type. A `Decimal128(2, 1)` holding `9.9`
    came back as `Decimal128(38, 10)` and read as `0.0000000099`. All four
    decimal widths behave this way, because the result is built through
    `unary_opt`, which uses `T::DATA_TYPE`. #11310 and #11321 fixed the same
    kind of bug.
    
    # What changes are included in this PR?
    
    - Set the input's data type on the `unary_opt` result with
    `.with_data_type(self.data_type().clone())`, as `into_builder` does
    since #11321.
    
    # Are these changes tested?
    
    Yes. `test_null_if_overflow_precision_keeps_data_type` covers
    Decimal32/64/128/256 at `(2, 1)`. Without the fix it fails with
    `Decimal32(9, 2)` vs `Decimal32(2, 1)`.
    
    # Are there any significant user-facing changes?
    
    The output data type now matches the input, including precision and
    scale. Which values get nulled is unchanged. Callers that re-applied the
    type afterwards (for example with `.with_precision_and_scale(..)`) keep
    working.
    
    # AI usage disclosure
    
    The patch and test were written with an AI coding agent (Claude Code).
    It reproduced the issue on main, ran fmt, clippy, the arrow-array tests
    (including release mode) and typos, and a separate agent session
    re-checked the fix against all four decimal widths, nulls, slices and
    the precision bounds before I submitted it.
---
 arrow-array/src/array/primitive_array.rs | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/arrow-array/src/array/primitive_array.rs 
b/arrow-array/src/array/primitive_array.rs
index a3f2d87dc5..f9cd7a2084 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -1726,6 +1726,7 @@ impl<T: DecimalType + ArrowPrimitiveType> 
PrimitiveArray<T> {
     /// will be casted to Null
     pub fn null_if_overflow_precision(&self, precision: u8) -> Self {
         self.unary_opt::<_, T>(|v| T::is_valid_decimal_precision(v, 
precision).then_some(v))
+            .with_data_type(self.data_type().clone())
     }
 
     /// Returns [`Self::value`] formatted as a string
@@ -2797,6 +2798,29 @@ mod tests {
         assert_eq!(result, expected);
     }
 
+    #[test]
+    fn test_null_if_overflow_precision_keeps_data_type() {
+        let array = Decimal32Array::from(vec![99])
+            .with_precision_and_scale(2, 1)
+            .unwrap();
+        assert_eq!(array.null_if_overflow_precision(2), array);
+
+        let array = Decimal64Array::from(vec![99])
+            .with_precision_and_scale(2, 1)
+            .unwrap();
+        assert_eq!(array.null_if_overflow_precision(2), array);
+
+        let array = Decimal128Array::from(vec![99])
+            .with_precision_and_scale(2, 1)
+            .unwrap();
+        assert_eq!(array.null_if_overflow_precision(2), array);
+
+        let array = Decimal256Array::from(vec![i256::from(99)])
+            .with_precision_and_scale(2, 1)
+            .unwrap();
+        assert_eq!(array.null_if_overflow_precision(2), array);
+    }
+
     #[test]
     fn test_decimal256_iter() {
         let mut builder = Decimal256Builder::with_capacity(30);

Reply via email to