sdf-jkl commented on code in PR #9563:
URL: https://github.com/apache/arrow-rs/pull/9563#discussion_r2988899564


##########
parquet-variant/src/variant.rs:
##########
@@ -760,10 +779,34 @@ impl<'m, 'v> Variant<'m, 'v> {
         }
     }
 
+    /// Converts a boolean or numeric variant to the specified numeric type 
`T`.
+    ///
+    /// Uses Arrow's casting logic to perform the conversion. Returns 
`Some(T)` if
+    /// the conversion succeeds, `None` if the variant can't be casted to type 
`T`.
+    fn as_num<T>(&self) -> Option<T>
+    where
+        T: NumCast + Default,
+    {
+        match *self {
+            Variant::BooleanFalse => single_bool_to_numeric::<T>(false),
+            Variant::BooleanTrue => single_bool_to_numeric::<T>(true),
+            Variant::Int8(i) => num_cast::<_, T>(i),
+            Variant::Int16(i) => num_cast::<_, T>(i),
+            Variant::Int32(i) => num_cast::<_, T>(i),
+            Variant::Int64(i) => num_cast::<_, T>(i),
+            Variant::Float(f) => num_cast::<_, T>(f),
+            Variant::Double(d) => num_cast::<_, T>(d),
+            Variant::Decimal4(d) if d.scale() == 0 => num_cast::<_, 
T>(d.integer()),
+            Variant::Decimal8(d) if d.scale() == 0 => num_cast::<_, 
T>(d.integer()),
+            Variant::Decimal16(d) if d.scale() == 0 => num_cast::<_, 
T>(d.integer()),
+            _ => None,
+        }
+    }
+
     /// Converts this variant to an `i8` if possible.
     ///
-    /// Returns `Some(i8)` for integer variants that fit in `i8` range,
-    /// `None` for non-integer variants or values that would overflow.
+    /// Returns `Some(i8)` for integer variants that fit in `i8` range and 
boolean variant,

Review Comment:
   Same for other type casts



-- 
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