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

Commit

Permalink
Added Offsets and OffsetsBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Dec 6, 2022
1 parent 9ea25f0 commit 832a02f
Show file tree
Hide file tree
Showing 72 changed files with 1,160 additions and 1,301 deletions.
5 changes: 2 additions & 3 deletions benches/iter_list.rs
Expand Up @@ -16,8 +16,7 @@ fn add_benchmark(c: &mut Criterion) {
let values = Buffer::from_iter(0..size as i32);
let values = PrimitiveArray::<i32>::from_data(DataType::Int32, values, None);

let mut offsets = (0..size as i32).step_by(2).collect::<Vec<_>>();
offsets.push(size as i32);
let offsets = (0..=size as i32).step_by(2).collect::<Vec<_>>();

let validity = (0..(offsets.len() - 1))
.map(|i| i % 4 == 0)
Expand All @@ -26,7 +25,7 @@ fn add_benchmark(c: &mut Criterion) {
let data_type = ListArray::<i32>::default_datatype(DataType::Int32);
let array = ListArray::<i32>::from_data(
data_type,
offsets.into(),
offsets.try_into().unwrap(),
Box::new(values),
Some(validity),
);
Expand Down
15 changes: 8 additions & 7 deletions src/array/binary/ffi.rs
Expand Up @@ -2,7 +2,7 @@ use crate::{
array::{FromFfi, ToFfi},
bitmap::align,
ffi,
offset::Offset,
offset::{Offset, OffsetsBuffer},
};

use crate::error::Result;
Expand All @@ -13,13 +13,13 @@ unsafe impl<O: Offset> ToFfi for BinaryArray<O> {
fn buffers(&self) -> Vec<Option<*const u8>> {
vec![
self.validity.as_ref().map(|x| x.as_ptr()),
Some(self.offsets.as_ptr().cast::<u8>()),
Some(self.offsets.buffer().as_ptr().cast::<u8>()),
Some(self.values.as_ptr().cast::<u8>()),
]
}

fn offset(&self) -> Option<usize> {
let offset = self.offsets.offset();
let offset = self.offsets.buffer().offset();
if let Some(bitmap) = self.validity.as_ref() {
if bitmap.offset() == offset {
Some(offset)
Expand All @@ -32,7 +32,7 @@ unsafe impl<O: Offset> ToFfi for BinaryArray<O> {
}

fn to_ffi_aligned(&self) -> Self {
let offset = self.offsets.offset();
let offset = self.offsets.buffer().offset();

let validity = self.validity.as_ref().map(|bitmap| {
if bitmap.offset() == offset {
Expand All @@ -59,8 +59,9 @@ impl<O: Offset, A: ffi::ArrowArrayRef> FromFfi<A> for BinaryArray<O> {
let offsets = unsafe { array.buffer::<O>(1) }?;
let values = unsafe { array.buffer::<u8>(2) }?;

Ok(Self::from_data_unchecked(
data_type, offsets, values, validity,
))
// assumption that data from FFI is well constructed
let offsets = unsafe { OffsetsBuffer::new_unchecked(offsets) };

Ok(Self::new(data_type, offsets, values, validity))
}
}

0 comments on commit 832a02f

Please sign in to comment.