From c6851103cac67f6001e8c6720f63e9e1d2496011 Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Tue, 31 Dec 2024 12:34:00 +0000 Subject: [PATCH] feat(arrow-array): add `BinaryArrayType` similar to `StringArrayType` --- arrow-array/src/array/mod.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arrow-array/src/array/mod.rs b/arrow-array/src/array/mod.rs index 23b3cb628aaf..0c135a9b68b4 100644 --- a/arrow-array/src/array/mod.rs +++ b/arrow-array/src/array/mod.rs @@ -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 + Sized { + /// Constructs a new iterator + fn iter(&self) -> ArrayIter; +} + +impl<'a, O: OffsetSizeTrait> BinaryArrayType<'a> for &'a GenericBinaryArray { + fn iter(&self) -> ArrayIter { + GenericBinaryArray::::iter(self) + } +} + +impl<'a> BinaryArrayType<'a> for &'a BinaryViewArray { + fn iter(&self) -> ArrayIter { + BinaryViewArray::iter(self) + } +} + +impl<'a> BinaryArrayType<'a> for &'a FixedSizeBinaryArray { + fn iter(&self) -> ArrayIter { + FixedSizeBinaryArray::iter(self) + } +} + impl PartialEq for dyn Array + '_ { fn eq(&self, other: &Self) -> bool { self.to_data().eq(&other.to_data())