diff --git a/arrow/src/compute/kernels/cast.rs b/arrow/src/compute/kernels/cast.rs index 7e9d1a147f9..4ffb1ea5d10 100644 --- a/arrow/src/compute/kernels/cast.rs +++ b/arrow/src/compute/kernels/cast.rs @@ -105,39 +105,7 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool { | FixedSizeList(_, _) | Struct(_) | Map(_, _) - | Dictionary(_, _), - ) - | ( - Boolean - | Int8 - | UInt8 - | Int16 - | UInt16 - | Int32 - | UInt32 - | Float32 - | Date32 - | Time32(_) - | Int64 - | UInt64 - | Float64 - | Date64 - | Timestamp(_, _) - | Time64(_) - | Duration(_) - | Interval(_) - | FixedSizeBinary(_) - | Binary - | Utf8 - | LargeBinary - | LargeUtf8 - | List(_) - | LargeList(_) - | FixedSizeList(_, _) - | Struct(_) - | Map(_, _) - | Dictionary(_, _), - Null, + | Dictionary(_, _) ) => true, (Decimal(_, _), _) => false, (_, Decimal(_, _)) => false, @@ -514,38 +482,6 @@ pub fn cast_with_options( | Struct(_) | Map(_, _) | Dictionary(_, _), - ) - | ( - Boolean - | Int8 - | UInt8 - | Int16 - | UInt16 - | Int32 - | UInt32 - | Float32 - | Date32 - | Time32(_) - | Int64 - | UInt64 - | Float64 - | Date64 - | Timestamp(_, _) - | Time64(_) - | Duration(_) - | Interval(_) - | FixedSizeBinary(_) - | Binary - | Utf8 - | LargeBinary - | LargeUtf8 - | List(_) - | LargeList(_) - | FixedSizeList(_, _) - | Struct(_) - | Map(_, _) - | Dictionary(_, _), - Null, ) => Ok(new_null_array(to_type, array.len())), (Struct(_), _) => Err(ArrowError::CastError( "Cannot cast from struct to other types".to_string(), @@ -4347,14 +4283,6 @@ mod tests { assert_eq!(cast_array.data_type(), &cast_type); assert_eq!(cast_array, &expected); } - { - let array = Arc::new($ARR_TYPE::from(vec![None; 4])) as ArrayRef; - let expected = NullArray::new(4); - let cast_array = cast(&array, &DataType::Null).expect("cast failed"); - let cast_array = as_null_array(&cast_array); - assert_eq!(cast_array.data_type(), &DataType::Null); - assert_eq!(cast_array, &expected); - } }}; } @@ -4373,17 +4301,7 @@ mod tests { typed_test!(Date64Array, Date64, Date64Type); } - fn cast_from_and_to_null(data_type: &DataType) { - // Cast from data_type to null - { - let array = new_null_array(data_type, 4); - 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)); - } - } + fn cast_from_null_to_other(data_type: &DataType) { // Cast from null to data_type { let array = new_null_array(&DataType::Null, 4); @@ -4398,10 +4316,10 @@ mod tests { #[test] fn test_cast_null_from_and_to_variable_sized() { - cast_from_and_to_null(&DataType::Utf8); - cast_from_and_to_null(&DataType::LargeUtf8); - cast_from_and_to_null(&DataType::Binary); - cast_from_and_to_null(&DataType::LargeBinary); + cast_from_null_to_other(&DataType::Utf8); + cast_from_null_to_other(&DataType::LargeUtf8); + cast_from_null_to_other(&DataType::Binary); + cast_from_null_to_other(&DataType::LargeBinary); } #[test] @@ -4418,32 +4336,32 @@ mod tests { )), false, ); - cast_from_and_to_null(&data_type); + cast_from_null_to_other(&data_type); // Cast null from and to list let data_type = DataType::List(Box::new(Field::new("item", DataType::Int32, true))); - cast_from_and_to_null(&data_type); + cast_from_null_to_other(&data_type); let data_type = DataType::LargeList(Box::new(Field::new("item", DataType::Int32, true))); - cast_from_and_to_null(&data_type); + cast_from_null_to_other(&data_type); let data_type = DataType::FixedSizeList( Box::new(Field::new("item", DataType::Int32, true)), 4, ); - cast_from_and_to_null(&data_type); + cast_from_null_to_other(&data_type); // Cast null from and to dictionary let values = vec![None, None, None, None] as Vec>; let array: DictionaryArray = values.into_iter().collect(); let array = Arc::new(array) as ArrayRef; let data_type = array.data_type().to_owned(); - cast_from_and_to_null(&data_type); + cast_from_null_to_other(&data_type); // Cast null from and to struct let data_type = DataType::Struct(vec![Field::new("data", DataType::Int64, false)]); - cast_from_and_to_null(&data_type); + cast_from_null_to_other(&data_type); } /// Print the `DictionaryArray` `array` as a vector of strings