From fa118e28d0f7379e918f8f62e73a8dc23c7997a6 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 21 Nov 2024 16:47:33 +0100 Subject: [PATCH] Add an arrow1 interface on top of `ArrowBuffer` --- .../store/re_types_core/src/arrow_buffer.rs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/store/re_types_core/src/arrow_buffer.rs b/crates/store/re_types_core/src/arrow_buffer.rs index f78831bccdb9..f386770efa15 100644 --- a/crates/store/re_types_core/src/arrow_buffer.rs +++ b/crates/store/re_types_core/src/arrow_buffer.rs @@ -1,15 +1,13 @@ -use arrow2::buffer::Buffer; - -/// Convenience-wrapper around an arrow [`Buffer`] that is known to contain a +/// Convenience-wrapper around an [`arrow2::buffer::Buffer`] that is known to contain a /// a primitive type. /// -/// The arrow2 [`Buffer`] object is internally reference-counted and can be +/// The [`ArrowBuffer`] object is internally reference-counted and can be /// easily converted back to a `&[T]` referencing the underlying storage. /// This avoids some of the lifetime complexities that would otherwise /// arise from returning a `&[T]` directly, but is significantly more /// performant than doing the full allocation necessary to return a `Vec`. #[derive(Clone, Debug, Default, PartialEq)] -pub struct ArrowBuffer(Buffer); +pub struct ArrowBuffer(arrow2::buffer::Buffer); impl crate::SizeBytes for ArrowBuffer { #[inline] @@ -50,7 +48,7 @@ impl ArrowBuffer { self.0.as_slice() } - /// Returns a new [`Buffer`] that is a slice of this buffer starting at `offset`. + /// Returns a new [`ArrowBuffer`] that is a slice of this buffer starting at `offset`. /// /// Doing so allows the same memory region to be shared between buffers. /// @@ -95,9 +93,18 @@ impl ArrowBuffer { } } -impl From> for ArrowBuffer { +impl + From> for ArrowBuffer +{ + #[inline] + fn from(value: arrow::buffer::ScalarBuffer) -> Self { + Self(value.into_inner().into()) + } +} + +impl From> for ArrowBuffer { #[inline] - fn from(value: Buffer) -> Self { + fn from(value: arrow2::buffer::Buffer) -> Self { Self(value) } } @@ -118,7 +125,7 @@ impl From<&[T]> for ArrowBuffer { impl FromIterator for ArrowBuffer { fn from_iter>(iter: I) -> Self { - Self(Buffer::from_iter(iter)) + Self(arrow2::buffer::Buffer::from_iter(iter)) } }