klion26 commented on code in PR #9563:
URL: https://github.com/apache/arrow-rs/pull/9563#discussion_r2939888805
##########
parquet-variant/src/variant.rs:
##########
@@ -1195,15 +1171,7 @@ impl<'m, 'v> Variant<'m, 'v> {
/// let v4 = Variant::from("hello!");
/// assert_eq!(v4.as_f16(), None);
pub fn as_f16(&self) -> Option<f16> {
- match *self {
- Variant::Float(i) => Some(f16::from_f32(i)),
- Variant::Double(i) => Some(f16::from_f64(i)),
- Variant::Int8(i) => Some(i.into()),
- Variant::Int16(i) if fits_precision::<11>(i) =>
Some(f16::from_f32(i as _)),
- Variant::Int32(i) if fits_precision::<11>(i) =>
Some(f16::from_f32(i as _)),
- Variant::Int64(i) if fits_precision::<11>(i) =>
Some(f16::from_f32(i as _)),
- _ => None,
- }
+ self.as_num::<f16>()
Review Comment:
This will change the behavior from before. Now `65536` will return
`Some(inf)` instead of None.
##########
parquet-variant/src/variant.rs:
##########
@@ -760,6 +771,26 @@ impl<'m, 'v> Variant<'m, 'v> {
}
}
+ 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::<i8, T>(i),
+ Variant::Int16(i) => num_cast::<i16, T>(i),
+ Variant::Int32(i) => num_cast::<i32, T>(i),
+ Variant::Int64(i) => num_cast::<i64, T>(i),
+ Variant::Float(f) => num_cast::<f32, T>(f),
+ Variant::Double(d) => num_cast::<f64, T>(d),
+ Variant::Decimal4(d) if d.scale() == 0 => num_cast::<_,
T>(d.integer()),
Review Comment:
`from/to_decimal` needs to be added in a following commit if the direction
is right
--
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]