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 3a35598892 fix: finish methods in `PrimitiveDictionaryBuilder` discard 
type params (#11327)
3a35598892 is described below

commit 3a355988921a28b90855ea8a866223baf3f0e5e1
Author: Neil Conway <[email protected]>
AuthorDate: Thu Oct 1 22:12:55 2026 -0400

    fix: finish methods in `PrimitiveDictionaryBuilder` discard type params 
(#11327)
    
    # Which issue does this PR close?
    
    - Relates to #3972
    
    # Rationale for this change
    
    `PrimitiveDictionaryBuilder::finish_cloned` and `finish_preserve_values`
    built the dictionary with `V::DATA_TYPE`, which is the default
    `DataType` for the dictionary's value type. This loses type parameters,
    like the scale/precision of a decimal value.
    
    A similar bug was fixed for `finish` in #3972, but `finish_cloned` and
    `finish_preserve_values` was missed.
    
    # What changes are included in this PR?
    
    See above.
    
    # Are these changes tested?
    
    Yes; existing tests pass, test expanded to cover this behavior. Verified
    that the updated test fails without the behavior change.
    
    # Are there any user-facing changes?
    
    No.
    
    # AI usage
    
    Bug found and fix developed with Claude Code (Opus 5.5); I have reviewed
    and understand the resulting code.
---
 .../src/builder/primitive_dictionary_builder.rs     | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/arrow-array/src/builder/primitive_dictionary_builder.rs 
b/arrow-array/src/builder/primitive_dictionary_builder.rs
index bc5d878500..f2ab6a49d3 100644
--- a/arrow-array/src/builder/primitive_dictionary_builder.rs
+++ b/arrow-array/src/builder/primitive_dictionary_builder.rs
@@ -459,7 +459,8 @@ where
         let values = self.values_builder.finish_cloned();
         let keys = self.keys_builder.finish_cloned();
 
-        let data_type = DataType::Dictionary(Box::new(K::DATA_TYPE), 
Box::new(V::DATA_TYPE));
+        let data_type =
+            DataType::Dictionary(Box::new(K::DATA_TYPE), 
Box::new(values.data_type().clone()));
 
         let builder = keys
             .into_data()
@@ -492,7 +493,8 @@ where
         let values = self.values_builder.finish_cloned();
         let keys = self.keys_builder.finish();
 
-        let data_type = DataType::Dictionary(Box::new(K::DATA_TYPE), 
Box::new(V::DATA_TYPE));
+        let data_type =
+            DataType::Dictionary(Box::new(K::DATA_TYPE), 
Box::new(values.data_type().clone()));
 
         let builder = keys
             .into_data()
@@ -604,15 +606,16 @@ mod tests {
                 keys_builder,
                 values_builder,
             );
+        let expected = DataType::Dictionary(
+            Box::new(DataType::Int32),
+            Box::new(DataType::Decimal128(1, 2)),
+        );
+        assert_eq!(builder.finish_cloned().data_type(), &expected);
+        assert_eq!(builder.finish_preserve_values().data_type(), &expected);
+
         let dict_array = builder.finish();
         assert_eq!(dict_array.value_type(), DataType::Decimal128(1, 2));
-        assert_eq!(
-            dict_array.data_type(),
-            &DataType::Dictionary(
-                Box::new(DataType::Int32),
-                Box::new(DataType::Decimal128(1, 2)),
-            )
-        );
+        assert_eq!(dict_array.data_type(), &expected);
     }
 
     #[test]

Reply via email to