diff --git a/arrow/src/array/array.rs b/arrow/src/array/array.rs index 1ad01f4f0d4..ea813a3cc5f 100644 --- a/arrow/src/array/array.rs +++ b/arrow/src/array/array.rs @@ -555,7 +555,18 @@ pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef { }) } DataType::Decimal(_, _) => { - unimplemented!("Creating null Decimal array not yet supported") + let null_buf: Buffer = MutableBuffer::new_null(length).into(); + make_array(unsafe { + ArrayData::new_unchecked( + data_type.clone(), + length, + Some(length), + Some(null_buf.clone()), + 0, + vec![null_buf], + vec![], + ) + }) } } } diff --git a/arrow/src/compute/kernels/cast.rs b/arrow/src/compute/kernels/cast.rs index 3e0d8f5ce04..b827ae31c18 100644 --- a/arrow/src/compute/kernels/cast.rs +++ b/arrow/src/compute/kernels/cast.rs @@ -96,6 +96,7 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool { | Int64 | UInt64 | Float64 + | Decimal(_, _) | Date64 | Timestamp(_, _) | Time64(_) @@ -127,6 +128,7 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool { | Int64 | UInt64 | Float64 + | Decimal(_, _) | Date64 | Timestamp(_, _) | Time64(_) @@ -509,6 +511,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 @@ -543,6 +546,7 @@ pub fn cast_with_options( Utf8 => { cast_string_to_decimal!(array, StringArray, precision, scale) } + Null => Ok(new_null_array(to_type, array.len())), _ => Err(ArrowError::CastError(format!( "Casting from {:?} to {:?} not supported", from_type, to_type