From bc3a40704cfc094e79c908cd53d219f6e6b3ee9d Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Wed, 15 Feb 2023 21:13:56 +0100 Subject: [PATCH] Added cast for FixedSizeBinary to (Large)Binary (#1403) --- src/compute/cast/binary_to.rs | 25 +++++-------------------- src/compute/cast/mod.rs | 4 ++-- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/compute/cast/binary_to.rs b/src/compute/cast/binary_to.rs index 37f4f8649aa..d84c7dd1bd4 100644 --- a/src/compute/cast/binary_to.rs +++ b/src/compute/cast/binary_to.rs @@ -130,29 +130,14 @@ fn fixed_size_to_offsets(values_len: usize, fixed_size: usize) -> Off unsafe { Offsets::new_unchecked(offsets) } } -/// Conversion of large-binary -pub fn fixed_size_binary_to_large_binary( +/// Conversion of `FixedSizeBinary` to `Binary`. +pub fn fixed_size_binary_binary( from: &FixedSizeBinaryArray, to_data_type: DataType, -) -> BinaryArray { +) -> BinaryArray { let values = from.values().clone(); - let offsets = fixed_size_to_offsets(values.len(), from.fixed_size()); - BinaryArray::::new( - to_data_type, - offsets.into(), - values, - from.validity().cloned(), - ) -} - -/// Conversion of binary -pub fn fixed_size_binary_to_binary( - from: &FixedSizeBinaryArray, - to_data_type: DataType, -) -> BinaryArray { - let values = from.values().clone(); - let offsets = fixed_size_to_offsets(values.len(), from.fixed_size()); - BinaryArray::::new( + let offsets = fixed_size_to_offsets(values.len(), from.size()); + BinaryArray::::new( to_data_type, offsets.into(), values, diff --git a/src/compute/cast/mod.rs b/src/compute/cast/mod.rs index 681602196e3..e42f769e7e5 100644 --- a/src/compute/cast/mod.rs +++ b/src/compute/cast/mod.rs @@ -687,12 +687,12 @@ pub fn cast(array: &dyn Array, to_type: &DataType, options: CastOptions) -> Resu ))), }, (FixedSizeBinary(_), _) => match to_type { - Binary => Ok(fixed_size_binary_to_binary( + Binary => Ok(fixed_size_binary_binary::( array.as_any().downcast_ref().unwrap(), to_type.clone(), ) .boxed()), - LargeBinary => Ok(fixed_size_binary_to_large_binary( + LargeBinary => Ok(fixed_size_binary_binary::( array.as_any().downcast_ref().unwrap(), to_type.clone(), )