Skip to content

Commit

Permalink
Remove arrow buffer conversion trait
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrobbel committed Mar 26, 2024
1 parent af7a5bf commit 5043c11
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 54 deletions.
6 changes: 3 additions & 3 deletions src/arrow/bitmap.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Interop with [`arrow-rs`] null buffer for bitmaps.
use crate::{arrow::buffer::Buffer, bitmap::Bitmap, buffer::BufferType, Length};
use crate::{bitmap::Bitmap, buffer::BufferType, Length};

impl<Buffer: BufferType> From<Bitmap<Buffer>> for arrow_buffer::BooleanBuffer
where
<Buffer as BufferType>::Buffer<u8>: crate::arrow::buffer::Buffer<u8>,
<Buffer as BufferType>::Buffer<u8>: Into<arrow_buffer::Buffer>,
{
fn from(value: Bitmap<Buffer>) -> Self {
Self::new(value.buffer.into_buffer(), value.offset, value.bits)
Self::new(value.buffer.into(), value.offset, value.bits)
}
}

Expand Down
51 changes: 0 additions & 51 deletions src/arrow/buffer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,60 +1,9 @@
//! Interop with [`arrow-rs`] buffer types.
use std::{ptr::NonNull, sync::Arc};

use arrow_buffer::alloc::Allocation;

use crate::FixedSize;

mod boolean_buffer;
mod null_buffer;

mod buffer_builder;
pub use buffer_builder::BufferBuilder;
mod scalar_buffer;
pub use scalar_buffer::ScalarBuffer;

/// Arrow compatible buffer types.
pub trait Buffer<T: FixedSize>: crate::buffer::Buffer<T>
where
Self: Sized + arrow_buffer::alloc::Allocation + 'static,
{
/// Converts this buffer into an [`arrow_buffer::Buffer`].
fn into_buffer(self) -> arrow_buffer::Buffer {
let len = self.len();
// Safety:
// - Buffers are required to correctly implement length.
unsafe {
arrow_buffer::Buffer::from_custom_allocation(
NonNull::new(self.as_bytes().as_ptr().cast_mut()).expect("buffer ptr is null"),
len,
Arc::new(self),
)
}
}

/// Converts this buffer into an [`arrow_buffer::ScalarBuffer<T>`].
fn into_scalar_buffer(self) -> arrow_buffer::ScalarBuffer<T> {
let len = self.len();
arrow_buffer::ScalarBuffer::new(self.into_buffer(), 0, len)
}
}

impl<T: FixedSize, U: Allocation + 'static> Buffer<T> for U where U: crate::buffer::Buffer<T> {}

/// Arrow compatible mutable buffer types.
pub trait BufferMut<T: FixedSize>: Buffer<T> + crate::buffer::BufferMut<T> {
/// Copies this buffer into an [`arrow_buffer::MutableBuffer`].
fn mutable_buffer(&self) -> arrow_buffer::MutableBuffer {
let mut mutable_buffer = arrow_buffer::MutableBuffer::new(self.len());
mutable_buffer.extend_from_slice(self.as_slice());
mutable_buffer
}

/// Copies this buffer into an [`arrow_buffer::BufferBuilder<T>`].
fn buffer_builder(&self) -> arrow_buffer::BufferBuilder<T> {
arrow_buffer::BufferBuilder::new_from_buffer(self.mutable_buffer())
}
}

impl<T: FixedSize, U: Allocation + 'static> BufferMut<T> for U where U: crate::buffer::BufferMut<T> {}

0 comments on commit 5043c11

Please sign in to comment.