You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/04/01 09:24:07 UTC

[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3996: Handle precision overflow when casting from integer to decimal

tustvold commented on code in PR #3996:
URL: https://github.com/apache/arrow-rs/pull/3996#discussion_r1155083792


##########
arrow-cast/src/cast.rs:
##########
@@ -8132,4 +8145,24 @@ mod tests {
             .unwrap();
         assert_eq!(1672531200000000000, c.value(0));
     }
+
+    #[test]
+    fn test_cast_numeric_to_decimal128_precision_overflow() {
+        let array = Int64Array::from(vec![1234567]);
+        let array = Arc::new(array) as ArrayRef;
+        let casted_array = cast_with_options(
+            &array,
+            &DataType::Decimal128(7, 3),
+            &CastOptions { safe: true },
+        );
+        assert!(casted_array.is_ok());
+        assert!(casted_array.unwrap().is_null(0));
+
+        let casted_array = cast_with_options(
+            &array,
+            &DataType::Decimal128(7, 3),
+            &CastOptions { safe: false },
+        );
+        assert!(casted_array.is_err());

Review Comment:
   Perhaps could check the error



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org