-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Support casting NULL to/from Decimal
#1922
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
Changes from 1 commit
369b203
5bcfde9
fad7452
46d022d
3a7344a
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,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool { | |
| // cast one decimal type to another decimal type | ||
| (Decimal(_, _), Decimal(_, _)) => true, | ||
| // signed numeric to decimal | ||
| (Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) | | ||
| (Null|Int8 | Int16 | Int32 | Int64 | Float32 | Float64, Decimal(_, _)) | | ||
| // decimal to signed numeric | ||
| (Decimal(_, _), Int8 | Int16 | Int32 | Int64 | Float32 | Float64) | ||
| (Decimal(_, _), Null| Int8 | Int16 | Int32 | Int64 | Float32 | Float64) | ||
|
viirya marked this conversation as resolved.
Outdated
|
||
| | ( | ||
| Null, | ||
| Boolean | ||
|
|
@@ -447,6 +447,7 @@ pub fn cast_with_options( | |
| Float64 => { | ||
| cast_decimal_to_float!(array, scale, Float64Builder, f64) | ||
| } | ||
| Null => Ok(new_null_array(to_type, array.len())), | ||
| _ => Err(ArrowError::CastError(format!( | ||
| "Casting from {:?} to {:?} not supported", | ||
| from_type, to_type | ||
|
|
@@ -475,6 +476,7 @@ pub fn cast_with_options( | |
| Float64 => { | ||
| cast_floating_point_to_decimal!(array, Float64Array, precision, scale) | ||
| } | ||
| Null => Ok(new_null_array(to_type, array.len())), | ||
| _ => Err(ArrowError::CastError(format!( | ||
| "Casting from {:?} to {:?} not supported", | ||
| from_type, to_type | ||
|
|
@@ -4312,6 +4314,26 @@ mod tests { | |
| assert_eq!(array_to_strings(&cast_array), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_cast_null_array_to_from_decimal_array() { | ||
| let data_type = DataType::Decimal(12, 4); | ||
| let array = new_null_array(&DataType::Null, 4); | ||
| assert_eq!(array.data_type(), &DataType::Null); | ||
| let cast_array = cast(&array, &data_type).expect("cast failed"); | ||
| assert_eq!(cast_array.data_type(), &data_type); | ||
| for i in 0..4 { | ||
| assert!(cast_array.is_null(i)); | ||
| } | ||
|
|
||
| let array = new_null_array(&data_type, 4); | ||
|
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. Why not support casting
Contributor
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 will fill up |
||
| assert_eq!(array.data_type(), &data_type); | ||
| let cast_array = cast(&array, &DataType::Null).expect("cast failed"); | ||
| assert_eq!(cast_array.data_type(), &DataType::Null); | ||
| for i in 0..4 { | ||
| assert!(cast_array.is_null(i)); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_cast_null_array_from_and_to_primitive_array() { | ||
| macro_rules! typed_test { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.