Skip to content

Commit

Permalink
chore: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikkon committed Apr 17, 2024
1 parent af38d14 commit 82b6095
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 69 deletions.
56 changes: 27 additions & 29 deletions arrow-array/src/array/list_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use crate::array::{get_view_offsets, get_view_sizes, make_array, print_long_array};
use crate::array::{make_array, print_long_array};
use crate::builder::{GenericListViewBuilder, PrimitiveBuilder};
use crate::iterator::GenericListViewArrayIter;
use crate::{
Expand Down Expand Up @@ -50,7 +50,6 @@ pub struct GenericListViewArray<OffsetSize: OffsetSizeTrait> {
values: ArrayRef,
value_offsets: ScalarBuffer<OffsetSize>,
value_sizes: ScalarBuffer<OffsetSize>,
len: usize,
}

impl<OffsetSize: OffsetSizeTrait> Clone for GenericListViewArray<OffsetSize> {
Expand All @@ -61,7 +60,6 @@ impl<OffsetSize: OffsetSizeTrait> Clone for GenericListViewArray<OffsetSize> {
values: self.values.clone(),
value_offsets: self.value_offsets.clone(),
value_sizes: self.value_sizes.clone(),
len: self.len,
}
}
}
Expand Down Expand Up @@ -96,6 +94,24 @@ impl<OffsetSize: OffsetSizeTrait> GenericListViewArray<OffsetSize> {
values: ArrayRef,
nulls: Option<NullBuffer>,
) -> Result<Self, ArrowError> {

let len = offsets.len();
if let Some(n) = nulls.as_ref() {
if n.len() != len {
return Err(ArrowError::InvalidArgumentError(format!(
"Incorrect length of null buffer for {}ListViewArray, expected {len} got {}",
OffsetSize::PREFIX,
n.len(),
)));
}
}
if len != sizes.len() {
return Err(ArrowError::InvalidArgumentError(format!(
"Length of offsets buffer and sizes buffer must be equal for {}ListViewArray, got {} and {}",
OffsetSize::PREFIX, len, sizes.len()
)));
}

for i in 0..offsets.len() {
let length = values.len();
let offset = offsets[i].as_usize();
Expand All @@ -108,30 +124,15 @@ impl<OffsetSize: OffsetSizeTrait> GenericListViewArray<OffsetSize> {
length
)));
}
if offset + size > values.len() {
if offset.saturating_add(size) > values.len() {
return Err(ArrowError::InvalidArgumentError(format!(
"Invalid offset and size values for {}ListViewArray, offset: {}, size: {}, values.len(): {}",
OffsetSize::PREFIX, offset, size, values.len()
)));
}
}

let len = offsets.len();
if let Some(n) = nulls.as_ref() {
if n.len() != len {
return Err(ArrowError::InvalidArgumentError(format!(
"Incorrect length of null buffer for {}ListViewArray, expected {len} got {}",
OffsetSize::PREFIX,
n.len(),
)));
}
}
if len != sizes.len() {
return Err(ArrowError::InvalidArgumentError(format!(
"Length of offsets buffer and sizes buffer must be equal for {}ListViewArray, got {} and {}",
OffsetSize::PREFIX, len, sizes.len()
)));
}


if !field.is_nullable() && values.is_nullable() {
return Err(ArrowError::InvalidArgumentError(format!(
Expand All @@ -157,7 +158,6 @@ impl<OffsetSize: OffsetSizeTrait> GenericListViewArray<OffsetSize> {
values,
value_offsets: offsets,
value_sizes: sizes,
len,
})
}

Expand Down Expand Up @@ -185,7 +185,6 @@ impl<OffsetSize: OffsetSizeTrait> GenericListViewArray<OffsetSize> {
value_offsets: ScalarBuffer::new_zeroed(len),
value_sizes: ScalarBuffer::new_zeroed(len),
values,
len: 0usize,
}
}

Expand Down Expand Up @@ -298,7 +297,6 @@ impl<OffsetSize: OffsetSizeTrait> GenericListViewArray<OffsetSize> {
values: self.values.clone(),
value_offsets: self.value_offsets.slice(offset, length),
value_sizes: self.value_sizes.slice(offset, length),
len: length,
}
}

Expand Down Expand Up @@ -366,11 +364,11 @@ impl<OffsetSize: OffsetSizeTrait> Array for GenericListViewArray<OffsetSize> {
}

fn len(&self) -> usize {
self.len
self.values.len()
}

fn is_empty(&self) -> bool {
self.value_offsets.len() <= 1
self.values.is_empty()
}

fn offset(&self) -> usize {
Expand All @@ -384,6 +382,7 @@ impl<OffsetSize: OffsetSizeTrait> Array for GenericListViewArray<OffsetSize> {
fn get_buffer_memory_size(&self) -> usize {
let mut size = self.values.get_buffer_memory_size();
size += self.value_offsets.inner().capacity();
size += self.value_sizes.inner().capacity();
if let Some(n) = self.nulls.as_ref() {
size += n.buffer().capacity();
}
Expand All @@ -393,6 +392,7 @@ impl<OffsetSize: OffsetSizeTrait> Array for GenericListViewArray<OffsetSize> {
fn get_array_memory_size(&self) -> usize {
let mut size = std::mem::size_of::<Self>() + self.values.get_array_memory_size();
size += self.value_offsets.inner().capacity();
size += self.value_sizes.inner().capacity();
if let Some(n) = self.nulls.as_ref() {
size += n.buffer().capacity();
}
Expand Down Expand Up @@ -460,7 +460,6 @@ impl<OffsetSize: OffsetSizeTrait> From<FixedSizeListArray> for GenericListViewAr
values: value.values().clone(),
value_offsets: offsets,
value_sizes: sizes,
len: value.len(),
}
}
}
Expand Down Expand Up @@ -502,16 +501,15 @@ impl<OffsetSize: OffsetSizeTrait> GenericListViewArray<OffsetSize> {
let values = make_array(values);
// SAFETY:
// ArrayData is valid, and verified type above
let value_offsets = get_view_offsets(&data);
let value_sizes = get_view_sizes(&data);
let value_offsets = ScalarBuffer::new(data.buffers()[0].clone(), data.offset(), data.len());
let value_sizes = ScalarBuffer::new(data.buffers()[1].clone(), data.offset(), data.len());

Ok(Self {
data_type: data.data_type().clone(),
nulls: data.nulls().cloned(),
values,
value_offsets,
value_sizes,
len: data.len(),
})
}
}
Expand Down
24 changes: 0 additions & 24 deletions arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,30 +696,6 @@ unsafe fn get_offsets<O: ArrowNativeType>(data: &ArrayData) -> OffsetBuffer<O> {
}
}

/// Helper function that gets list view offset from an [`ArrayData`]
///
/// # Safety
///
/// ArrayData must contain a valid [`ScalarBuffer`] as its first buffer
fn get_view_offsets<O: ArrowNativeType>(data: &ArrayData) -> ScalarBuffer<O> {
match data.is_empty() && data.buffers()[0].is_empty() {
true => ScalarBuffer::new_empty(),
false => ScalarBuffer::new(data.buffers()[0].clone(), data.offset(), data.len() + 1),
}
}

/// Helper function that gets list view size from an [`ArrayData`]
///
/// # Safety
///
/// ArrayData must contain a valid [`ScalarBuffer`] as its second buffer
fn get_view_sizes<O: ArrowNativeType>(data: &ArrayData) -> ScalarBuffer<O> {
match data.is_empty() && data.buffers()[1].is_empty() {
true => ScalarBuffer::new_empty(),
false => ScalarBuffer::new(data.buffers()[1].clone(), data.offset(), data.len()),
}
}

/// Helper function for printing potentially long arrays.
fn print_long_array<A, F>(array: &A, f: &mut std::fmt::Formatter, print_item: F) -> std::fmt::Result
where
Expand Down
3 changes: 1 addition & 2 deletions arrow-array/src/builder/generic_list_view_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ where
pub fn append(&mut self, is_valid: bool, size: usize) {
self.offsets_builder
.append(OffsetSize::from_usize(self.values_builder.len() - size).unwrap());
let size = OffsetSize::from_usize(size).unwrap();
self.sizes_builder.append(size);
self.sizes_builder.append(OffsetSize::from_usize(self.values_builder.len()).unwrap());
self.null_buffer_builder.append(is_valid);
}

Expand Down
15 changes: 1 addition & 14 deletions arrow-data/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,17 +860,6 @@ impl ArrayData {
self.typed_buffer(0, self.len + 1)
}

/// Returns a reference to the data in `buffer` as a typed slice
/// after validating. The returned slice is guaranteed to have at
/// least `len` entries.
fn typed_sizes<T: ArrowNativeType + num::Num>(&self) -> Result<&[T], ArrowError> {
// An empty list-like array can have 0 sizes
if self.len == 0 && self.buffers[1].is_empty() {
return Ok(&[]);
}
self.typed_buffer(1, self.len)
}

/// Returns a reference to the data in `buffers[idx]` as a typed slice after validating
fn typed_buffer<T: ArrowNativeType + num::Num>(
&self,
Expand Down Expand Up @@ -948,7 +937,7 @@ impl ArrayData {
&self,
values_length: usize,
) -> Result<(), ArrowError> {
let sizes = self.typed_sizes::<T>()?;
let sizes: &[T] = self.typed_buffer(1, self.len)?;
if sizes.is_empty() {
return Ok(());
}
Expand All @@ -974,7 +963,6 @@ impl ArrayData {
}
DataType::ListView(field) => {
let values_data = self.get_single_valid_child_data(field.data_type())?;
self.validate_offsets::<i32>(values_data.len)?;
self.validate_sizes::<i32>(values_data.len)?;
Ok(())
}
Expand All @@ -985,7 +973,6 @@ impl ArrayData {
}
DataType::LargeListView(field) => {
let values_data = self.get_single_valid_child_data(field.data_type())?;
self.validate_offsets::<i64>(values_data.len)?;
self.validate_sizes::<i64>(values_data.len)?;
Ok(())
}
Expand Down

0 comments on commit 82b6095

Please sign in to comment.