Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 35 additions & 29 deletions arrow/src/array/array_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,6 @@ impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {
let value_offsets = data.buffers()[0].as_ptr();

let value_offsets = unsafe { RawPtrBox::<OffsetSize>::new(value_offsets) };
unsafe {
if !(*value_offsets.as_ptr().offset(0)).is_zero() {
return Err(ArrowError::InvalidArgumentError(String::from(
"offsets do not start at zero",
)));
}
}
Ok(Self {
data,
values,
Expand Down Expand Up @@ -1027,6 +1020,41 @@ mod tests {
assert_eq!(8, sliced_list_array.value_offset(3));
}

#[test]
fn test_list_array_offsets_need_not_start_at_zero() {
let value_data = ArrayData::builder(DataType::Int32)
.len(8)
.add_buffer(Buffer::from_slice_ref(&[0, 1, 2, 3, 4, 5, 6, 7]))
.build()
.unwrap();

let value_offsets = Buffer::from_slice_ref(&[2, 2, 5, 7]);

let list_data_type =
DataType::List(Box::new(Field::new("item", DataType::Int32, false)));
let list_data = ArrayData::builder(list_data_type)
.len(3)
.add_buffer(value_offsets)
.add_child_data(value_data)
.build()
.unwrap();

let list_array = make_array(list_data);
let list_array = list_array.as_any().downcast_ref::<ListArray>().unwrap();

assert_eq!(list_array.len(), 3);

assert!(list_array.value(0).is_empty());
assert_eq!(
list_array.value(1).as_ref(),
&PrimitiveArray::<Int32Type>::from(vec![2, 3, 4])
);
assert_eq!(
list_array.value(2).as_ref(),
&PrimitiveArray::<Int32Type>::from(vec![5, 6])
);
}

#[test]
#[should_panic(expected = "assertion failed: (offset + length) <= self.len()")]
fn test_fixed_size_list_array_index_out_of_bound() {
Expand Down Expand Up @@ -1100,28 +1128,6 @@ mod tests {
drop(ListArray::from(list_data));
}

#[test]
#[should_panic(expected = "offsets do not start at zero")]
fn test_list_array_invalid_value_offset_start() {
let value_data = ArrayData::builder(DataType::Int32)
.len(8)
.add_buffer(Buffer::from_slice_ref(&[0, 1, 2, 3, 4, 5, 6, 7]))
.build()
.unwrap();

let value_offsets = Buffer::from_slice_ref(&[2, 2, 5, 7]);

let list_data_type =
DataType::List(Box::new(Field::new("item", DataType::Int32, false)));
let list_data = ArrayData::builder(list_data_type)
.len(3)
.add_buffer(value_offsets)
.add_child_data(value_data)
.build()
.unwrap();
drop(ListArray::from(list_data));
}

#[test]
#[should_panic(expected = "memory is not aligned")]
fn test_primitive_array_alignment() {
Expand Down
7 changes: 0 additions & 7 deletions arrow/src/array/array_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ impl MapArray {
let value_offsets = data.buffers()[0].as_ptr();

let value_offsets = unsafe { RawPtrBox::<i32>::new(value_offsets) };
unsafe {
if (*value_offsets.as_ptr().offset(0)) != 0 {
return Err(ArrowError::InvalidArgumentError(String::from(
"offsets do not start at zero",
)));
}
}
Ok(Self {
data,
values,
Expand Down
Loading