Skip to content

Commit

Permalink
feat: Support cast between Decimal and Null
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou committed Jan 19, 2024
1 parent dbc9929 commit d55f664
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion arrow/src/array/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![],
)
})
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions arrow/src/compute/kernels/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
| Int64
| UInt64
| Float64
| Decimal(_, _)
| Date64
| Timestamp(_, _)
| Time64(_)
Expand Down Expand Up @@ -127,6 +128,7 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
| Int64
| UInt64
| Float64
| Decimal(_, _)
| Date64
| Timestamp(_, _)
| Time64(_)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d55f664

Please sign in to comment.