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


##########
arrow-cast/src/cast.rs:
##########
@@ -411,34 +412,51 @@ fn cast_reinterpret_arrays<
     ))
 }
 
-// cast the decimal array to integer array
-macro_rules! cast_decimal_to_integer {
-    ($ARRAY:expr, $SCALE : ident, $VALUE_BUILDER: ident, $NATIVE_TYPE : ident, 
$DATA_TYPE : expr) => {{
-        let array = $ARRAY.as_any().downcast_ref::<Decimal128Array>().unwrap();
-        let mut value_builder = $VALUE_BUILDER::with_capacity(array.len());
-        let div: i128 = 10_i128.pow(*$SCALE as u32);
-        let min_bound = ($NATIVE_TYPE::MIN) as i128;
-        let max_bound = ($NATIVE_TYPE::MAX) as i128;
-        for i in 0..array.len() {
-            if array.is_null(i) {
-                value_builder.append_null();
+fn cast_decimal_to_integer<D, T>(

Review Comment:
   Do we need to support castoptions here?



##########
arrow-cast/src/cast.rs:
##########
@@ -411,34 +412,51 @@ fn cast_reinterpret_arrays<
     ))
 }
 
-// cast the decimal array to integer array
-macro_rules! cast_decimal_to_integer {
-    ($ARRAY:expr, $SCALE : ident, $VALUE_BUILDER: ident, $NATIVE_TYPE : ident, 
$DATA_TYPE : expr) => {{
-        let array = $ARRAY.as_any().downcast_ref::<Decimal128Array>().unwrap();
-        let mut value_builder = $VALUE_BUILDER::with_capacity(array.len());
-        let div: i128 = 10_i128.pow(*$SCALE as u32);
-        let min_bound = ($NATIVE_TYPE::MIN) as i128;
-        let max_bound = ($NATIVE_TYPE::MAX) as i128;
-        for i in 0..array.len() {
-            if array.is_null(i) {
-                value_builder.append_null();
+fn cast_decimal_to_integer<D, T>(
+    array: &ArrayRef,
+    base: D::Native,
+    scale: u8,
+    max_bound: D::Native,

Review Comment:
   We could implement ToPrimitive for i256 and then use NumCast here?



##########
arrow-buffer/src/bigint.rs:
##########
@@ -457,6 +457,21 @@ macro_rules! define_as_primitive {
                 i256::from_i128(self as i128)
             }
         }
+
+        impl AsPrimitive<$native_ty> for i256 {
+            fn as_(self) -> $native_ty {
+                let integer = self.to_i128();

Review Comment:
   I think this should just be `self.low as _`?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to