From 93da1ff213fe966077e8c9d951a7ce7b4b4d23c8 Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Mon, 22 Nov 2021 17:05:01 +0100 Subject: [PATCH 1/2] add to conversion to fixedsizebinary --- src/array/fixed_size_binary/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/array/fixed_size_binary/mod.rs b/src/array/fixed_size_binary/mod.rs index 9baad61a504..959e9cd3b64 100644 --- a/src/array/fixed_size_binary/mod.rs +++ b/src/array/fixed_size_binary/mod.rs @@ -136,6 +136,18 @@ impl FixedSizeBinaryArray { .get_unchecked(i * self.size..(i + 1) * self.size) } + /// Returns a new [`FixedSizeBinary`] with a different logical type. + /// This is `O(1)`. + #[inline] + pub fn to(self, data_type: DataType) -> Self { + Self { + size: self.size, + data_type, + values: self.values, + validity: self.validity, + } + } + /// Returns the size pub fn size(&self) -> usize { self.size From ec52134c10982cc5c554eadf7ee094f6bb3a86b7 Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Tue, 23 Nov 2021 08:55:49 +0100 Subject: [PATCH 2/2] test type correctness --- src/array/fixed_size_binary/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/array/fixed_size_binary/mod.rs b/src/array/fixed_size_binary/mod.rs index 959e9cd3b64..e2eaaf08f0a 100644 --- a/src/array/fixed_size_binary/mod.rs +++ b/src/array/fixed_size_binary/mod.rs @@ -138,8 +138,19 @@ impl FixedSizeBinaryArray { /// 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,