From bc3da783a81739b62ea6bfef1db8451a5b861b51 Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Wed, 24 Nov 2021 08:04:17 +0100 Subject: [PATCH] Added `to` conversion to `FixedSizeBinary` (#622) --- src/array/fixed_size_binary/mod.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/array/fixed_size_binary/mod.rs b/src/array/fixed_size_binary/mod.rs index 9baad61a504..e2eaaf08f0a 100644 --- a/src/array/fixed_size_binary/mod.rs +++ b/src/array/fixed_size_binary/mod.rs @@ -136,6 +136,29 @@ impl FixedSizeBinaryArray { .get_unchecked(i * self.size..(i + 1) * self.size) } + /// Returns a new [`FixedSizeBinary`] with a different logical type. + /// This is `O(1)`. + /// # Panics + /// Panics iff the data_type is not supported for the physical type. + #[inline] + pub fn to(self, data_type: DataType) -> Self { + match ( + data_type.to_logical_type(), + self.data_type().to_logical_type(), + ) { + (DataType::FixedSizeBinary(size_a), DataType::FixedSizeBinary(size_b)) + if size_a == size_b => {} + _ => panic!("Wrong DataType"), + } + + Self { + size: self.size, + data_type, + values: self.values, + validity: self.validity, + } + } + /// Returns the size pub fn size(&self) -> usize { self.size