You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/11/27 21:18:21 UTC

[arrow-rs] branch master updated: Add a cast test case for decimal negative scale (#3203)

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

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 1daf7d31f Add a cast test case for decimal negative scale (#3203)
1daf7d31f is described below

commit 1daf7d31ff5a99fc47cc14328e2ab603dbe34679
Author: Liang-Chi Hsieh <vi...@gmail.com>
AuthorDate: Sun Nov 27 13:18:16 2022 -0800

    Add a cast test case for decimal negative scale (#3203)
    
    * Add a cast test case for decimal negative scale
    
    * Add one more test
---
 arrow-cast/src/cast.rs | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/arrow-cast/src/cast.rs b/arrow-cast/src/cast.rs
index 07c7d6a3a..1f5359bae 100644
--- a/arrow-cast/src/cast.rs
+++ b/arrow-cast/src/cast.rs
@@ -7437,4 +7437,40 @@ mod tests {
         assert_eq!("2120", decimal_arr.value_as_string(1));
         assert_eq!("3120", decimal_arr.value_as_string(2));
     }
+
+    #[test]
+    fn test_cast_decimal128_to_decimal128_negative() {
+        let input_type = DataType::Decimal128(10, -1);
+        let output_type = DataType::Decimal128(10, -2);
+        assert!(can_cast_types(&input_type, &output_type));
+        let array = vec![Some(123)];
+        let input_decimal_array = create_decimal_array(array, 10, -1).unwrap();
+        let array = Arc::new(input_decimal_array) as ArrayRef;
+        generate_cast_test_case!(
+            &array,
+            Decimal128Array,
+            &output_type,
+            vec![Some(12_i128),]
+        );
+
+        let casted_array = cast(&array, &output_type).unwrap();
+        let decimal_arr = as_primitive_array::<Decimal128Type>(&casted_array);
+
+        assert_eq!("1200", decimal_arr.value_as_string(0));
+
+        let array = vec![Some(125)];
+        let input_decimal_array = create_decimal_array(array, 10, -1).unwrap();
+        let array = Arc::new(input_decimal_array) as ArrayRef;
+        generate_cast_test_case!(
+            &array,
+            Decimal128Array,
+            &output_type,
+            vec![Some(13_i128),]
+        );
+
+        let casted_array = cast(&array, &output_type).unwrap();
+        let decimal_arr = as_primitive_array::<Decimal128Type>(&casted_array);
+
+        assert_eq!("1300", decimal_arr.value_as_string(0));
+    }
 }