klion26 commented on code in PR #9563:
URL: https://github.com/apache/arrow-rs/pull/9563#discussion_r2964585175
##########
parquet-variant/src/variant.rs:
##########
@@ -760,10 +779,30 @@ impl<'m, 'v> Variant<'m, 'v> {
}
}
+ fn as_num<T>(&self) -> Option<T>
Review Comment:
Done
##########
parquet-variant/src/variant.rs:
##########
@@ -844,31 +873,26 @@ impl<'m, 'v> Variant<'m, 'v> {
/// let v1 = Variant::from(123i64);
/// assert_eq!(v1.as_int32(), Some(123i32));
///
+ /// // or from boolean variant
+ /// let v2 = Variant::BooleanFalse;
+ /// assert_eq!(v2.as_int32(), Some(0));
+ ///
/// // but not if it would overflow
- /// let v2 = Variant::from(12345678901i64);
- /// assert_eq!(v2.as_int32(), None);
+ /// let v3 = Variant::from(12345678901i64);
+ /// assert_eq!(v3.as_int32(), None);
///
/// // or if the variant cannot be cast into an integer
- /// let v3 = Variant::from("hello!");
- /// assert_eq!(v3.as_int32(), None);
+ /// let v4 = Variant::from("hello!");
+ /// assert_eq!(v4.as_int32(), None);
/// ```
pub fn as_int32(&self) -> Option<i32> {
- match *self {
- Variant::Int8(i) => Some(i.into()),
- Variant::Int16(i) => Some(i.into()),
- Variant::Int32(i) => Some(i),
- Variant::Int64(i) => i.try_into().ok(),
- Variant::Decimal4(d) if d.scale() == 0 => Some(d.integer()),
- Variant::Decimal8(d) if d.scale() == 0 =>
d.integer().try_into().ok(),
- Variant::Decimal16(d) if d.scale() == 0 =>
d.integer().try_into().ok(),
- _ => None,
- }
+ self.as_num::<_>()
Review Comment:
Thanks for pointing this out. The inference has been removed now
--
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]