Skip to content

Commit

Permalink
feat(arrow-array): add BinaryArrayType similar to StringArrayType
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Dec 31, 2024
1 parent 5249f99 commit c685110
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,37 @@ impl<'a> StringArrayType<'a> for &'a StringViewArray {
}
}

/// A trait for Arrow Binary Arrays, currently the following types are supported:
/// - `BinaryArray`
/// - `LargeBinaryArray`
/// - `BinaryViewArray`
/// - `FixedSizeBinaryArray`
///
/// This trait helps to abstract over the different types of binary arrays
/// so that we don't need to duplicate the implementation for each type.
pub trait BinaryArrayType<'a>: ArrayAccessor<Item = &'a [u8]> + Sized {
/// Constructs a new iterator
fn iter(&self) -> ArrayIter<Self>;
}

impl<'a, O: OffsetSizeTrait> BinaryArrayType<'a> for &'a GenericBinaryArray<O> {
fn iter(&self) -> ArrayIter<Self> {
GenericBinaryArray::<O>::iter(self)
}
}

impl<'a> BinaryArrayType<'a> for &'a BinaryViewArray {
fn iter(&self) -> ArrayIter<Self> {
BinaryViewArray::iter(self)
}
}

impl<'a> BinaryArrayType<'a> for &'a FixedSizeBinaryArray {
fn iter(&self) -> ArrayIter<Self> {
FixedSizeBinaryArray::iter(self)
}
}

impl PartialEq for dyn Array + '_ {
fn eq(&self, other: &Self) -> bool {
self.to_data().eq(&other.to_data())
Expand Down

0 comments on commit c685110

Please sign in to comment.