-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Variant] Align cast logic for from/to_decimal for variant #9689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,9 +72,26 @@ use arrow_schema::*; | |
| use arrow_select::take::take; | ||
| use num_traits::{NumCast, ToPrimitive, cast::AsPrimitive}; | ||
|
|
||
| pub use decimal::{DecimalCast, rescale_decimal}; | ||
| pub use decimal::{ | ||
| DecimalCast, cast_single_decimal_to_integer, parse_string_to_decimal_native, rescale_decimal, | ||
| single_float_to_decimal, | ||
| }; | ||
| pub use string::cast_single_string_to_boolean_default; | ||
|
|
||
| /// Lossy conversion from decimal to float. | ||
| /// | ||
| /// Conversion is lossy and follows standard floating point semantics. Values | ||
| /// that exceed the representable range become `INFINITY` or `-INFINITY` without | ||
| /// returning an error. | ||
| #[inline] | ||
| pub fn single_decimal_to_float_lossy<D, F>(f: &F, x: D::Native, scale: i32) -> f64 | ||
| where | ||
| D: DecimalType, | ||
| F: Fn(D::Native) -> f64, | ||
| { | ||
| f(x) * 10_f64.powi(-scale) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rescuing #9689 (comment) from github oblivion... I just remembered that floating point
(emphasis mine) Whether we think any difference matters for this specific case... I don't know. But we should probably defer a change like this to its own PR with appropriate performance evaluation and weighing of trade-offs. At least there's now a narrow waist for such a future optimization to be made easily.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have the same question before changing the code, but the code on play rust below shows that they are equal, not sure if this is enought. yes, If this code below is not enough,we should keep it as it in the current pr
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pure luck that |
||
| } | ||
|
|
||
| /// CastOptions provides a way to override the default cast behaviors | ||
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
| pub struct CastOptions<'a> { | ||
|
|
@@ -2314,10 +2331,11 @@ where | |
| Int32 => cast_decimal_to_integer::<D, Int32Type>(array, base, *scale, cast_options), | ||
| Int64 => cast_decimal_to_integer::<D, Int64Type>(array, base, *scale, cast_options), | ||
| Float32 => cast_decimal_to_float::<D, Float32Type, _>(array, |x| { | ||
| (as_float(x) / 10_f64.powi(*scale as i32)) as f32 | ||
| single_decimal_to_float_lossy::<D, F>(&as_float, x, <i32 as From<i8>>::from(*scale)) | ||
| as f32 | ||
| }), | ||
| Float64 => cast_decimal_to_float::<D, Float64Type, _>(array, |x| { | ||
| as_float(x) / 10_f64.powi(*scale as i32) | ||
| single_decimal_to_float_lossy::<D, F>(&as_float, x, <i32 as From<i8>>::from(*scale)) | ||
| }), | ||
| Utf8View => value_to_string_view(array, cast_options), | ||
| Utf8 => value_to_string::<i32>(array, cast_options), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.