Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Added to conversion to FixedSizeBinary #622

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this? I assume we must check that the physical types are correct.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly, this works!

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
Expand Down