Skip to content

Commit

Permalink
Cleanup: remove some dead / test only code (#1331)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Feb 19, 2022
1 parent f4c7102 commit c0351f8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 81 deletions.
23 changes: 0 additions & 23 deletions arrow/src/array/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,29 +198,6 @@ pub(crate) fn new_buffers(data_type: &DataType, capacity: usize) -> [MutableBuff
}
}

/// Ensures that at least `min_size` elements of type `data_type` can
/// be stored in a buffer of `buffer_size`.
///
/// `buffer_index` is used in error messages to identify which buffer
/// had the invalid index
#[allow(dead_code)]
fn ensure_size(
data_type: &DataType,
min_size: usize,
buffer_size: usize,
buffer_index: usize,
) -> Result<()> {
// if min_size is zero, may not have buffers (e.g. NullArray)
if min_size > 0 && buffer_size < min_size {
Err(ArrowError::InvalidArgumentError(format!(
"Need at least {} bytes in buffers[{}] in array of type {:?}, but got {}",
buffer_size, buffer_index, data_type, min_size
)))
} else {
Ok(())
}
}

/// Maps 2 [`MutableBuffer`]s into a vector of [Buffer]s whose size depends on `data_type`.
#[inline]
pub(crate) fn into_buffers(
Expand Down
93 changes: 35 additions & 58 deletions arrow/src/compute/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Common utilities for computation kernels.

use crate::array::*;
use crate::buffer::{buffer_bin_and, buffer_bin_or, Buffer};
use crate::buffer::{buffer_bin_and, Buffer};
use crate::datatypes::*;
use crate::error::{ArrowError, Result};
use num::{One, ToPrimitive, Zero};
Expand Down Expand Up @@ -58,41 +58,6 @@ pub(super) fn combine_option_bitmap(
}
}

/// Compares the null bitmaps of two arrays using a bitwise `or` operation.
///
/// This function is useful when implementing operations on higher level arrays.
#[allow(clippy::unnecessary_wraps)]
#[allow(dead_code)]
pub(super) fn compare_option_bitmap(
left_data: &ArrayData,
right_data: &ArrayData,
len_in_bits: usize,
) -> Result<Option<Buffer>> {
let left_offset_in_bits = left_data.offset();
let right_offset_in_bits = right_data.offset();

let left = left_data.null_buffer();
let right = right_data.null_buffer();

match left {
None => match right {
None => Ok(None),
Some(r) => Ok(Some(r.bit_slice(right_offset_in_bits, len_in_bits))),
},
Some(l) => match right {
None => Ok(Some(l.bit_slice(left_offset_in_bits, len_in_bits))),

Some(r) => Ok(Some(buffer_bin_or(
l,
left_offset_in_bits,
r,
right_offset_in_bits,
len_in_bits,
))),
},
}
}

/// Takes/filters a list array's inner data using the offsets of the list array.
///
/// Where a list array has indices `[0,2,5,10]`, taking indices of `[2,0]` returns
Expand Down Expand Up @@ -176,10 +141,44 @@ pub(super) mod tests {

use std::sync::Arc;

use crate::buffer::buffer_bin_or;
use crate::datatypes::DataType;
use crate::util::bit_util;
use crate::{array::ArrayData, buffer::MutableBuffer};

/// Compares the null bitmaps of two arrays using a bitwise `or` operation.
///
/// This function is useful when implementing operations on higher level arrays.
pub(super) fn compare_option_bitmap(
left_data: &ArrayData,
right_data: &ArrayData,
len_in_bits: usize,
) -> Result<Option<Buffer>> {
let left_offset_in_bits = left_data.offset();
let right_offset_in_bits = right_data.offset();

let left = left_data.null_buffer();
let right = right_data.null_buffer();

match left {
None => match right {
None => Ok(None),
Some(r) => Ok(Some(r.bit_slice(right_offset_in_bits, len_in_bits))),
},
Some(l) => match right {
None => Ok(Some(l.bit_slice(left_offset_in_bits, len_in_bits))),

Some(r) => Ok(Some(buffer_bin_or(
l,
left_offset_in_bits,
r,
right_offset_in_bits,
len_in_bits,
))),
},
}
}

fn make_data_with_null_bit_buffer(
len: usize,
offset: usize,
Expand Down Expand Up @@ -344,28 +343,6 @@ pub(super) mod tests {
GenericListArray::<S>::from(list_data)
}

#[allow(dead_code)]
pub(crate) fn build_fixed_size_list<T>(
data: Vec<Option<Vec<T::Native>>>,
length: <Int32Type as ArrowPrimitiveType>::Native,
) -> FixedSizeListArray
where
T: ArrowPrimitiveType,
PrimitiveArray<T>: From<Vec<Option<T::Native>>>,
{
let data = data
.into_iter()
.map(|subarray| {
subarray.map(|item| {
item.into_iter()
.map(Some)
.collect::<Vec<Option<T::Native>>>()
})
})
.collect();
build_fixed_size_list_nullable(data, length)
}

pub(crate) fn build_fixed_size_list_nullable<T>(
list_values: Vec<Option<Vec<Option<T::Native>>>>,
length: <Int32Type as ArrowPrimitiveType>::Native,
Expand Down

0 comments on commit c0351f8

Please sign in to comment.