Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
format and fix clippy warnings
  • Loading branch information
HawaiianSpork committed Apr 14, 2026
commit b561083b2222d10d70888e4404335c51afabaccf
5 changes: 1 addition & 4 deletions arrow-data/src/transform/fixed_size_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ pub(super) fn build_extend(array: &ArrayData) -> Extend<'_> {
)
}

pub(super) fn extend_nulls(
mutable: &mut _MutableArrayData,
len: usize,
) -> Result<(), ArrowError> {
pub(super) fn extend_nulls(mutable: &mut _MutableArrayData, len: usize) -> Result<(), ArrowError> {
let size = match mutable.data_type {
DataType::FixedSizeList(_, i) => i as usize,
_ => unreachable!(),
Expand Down
6 changes: 1 addition & 5 deletions arrow-data/src/transform/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ pub(super) fn build_extend<T: ArrowNativeType + Integer + CheckedAdd>(
let last_offset: T = unsafe { get_last_offset(offset_buffer) };

// offsets
try_extend_offsets::<T>(
offset_buffer,
last_offset,
&offsets[start..start + len + 1],
)?;
try_extend_offsets::<T>(offset_buffer, last_offset, &offsets[start..start + len + 1])?;

mutable.child_data[0].try_extend(
index,
Expand Down
10 changes: 3 additions & 7 deletions arrow-data/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,7 @@ impl<'a> MutableArrayData<'a> {
/// This function panics if there is an invalid index,
/// i.e. `index` >= the number of source arrays
/// or `end` > the length of the `index`th array
pub fn try_extend(
&mut self,
index: usize,
start: usize,
end: usize,
) -> Result<(), ArrowError> {
pub fn try_extend(&mut self, index: usize, start: usize, end: usize) -> Result<(), ArrowError> {
let len = end - start;
(self.extend_null_bits[index])(&mut self.data, start, len);
// Snapshot buffer lengths before attempting the extend so we can roll
Expand All @@ -763,7 +758,6 @@ impl<'a> MutableArrayData<'a> {
Ok(())
}


/// Extends the in progress array with a region of the input arrays.
///
/// # Deprecated
Expand All @@ -776,6 +770,7 @@ impl<'a> MutableArrayData<'a> {
/// `end` > the length of the `index`th array,
/// or the offset type overflows (e.g. more than 2 GiB in a `StringArray`).
#[deprecated(
since = "59.0.0",
note = "Use `try_extend` which returns an error on overflow instead of panicking"
)]
pub fn extend(&mut self, index: usize, start: usize, end: usize) {
Expand Down Expand Up @@ -813,6 +808,7 @@ impl<'a> MutableArrayData<'a> {
/// Panics if [`MutableArrayData`] not created with `use_nulls` or nullable source arrays,
/// or if the run-end counter overflows for `RunEndEncoded` arrays.
#[deprecated(
since = "59.0.0",
note = "Use `try_extend_nulls` which returns an error on overflow instead of panicking"
)]
pub fn extend_nulls(&mut self, len: usize) {
Expand Down
35 changes: 22 additions & 13 deletions arrow-data/src/transform/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,17 @@ pub fn extend_nulls(mutable: &mut _MutableArrayData, len: usize) -> Result<(), A
Ok(())
}

/// The run-ends bytes and optional values index range returned by [`build_extend_arrays`].
type ExtendArrays = (Vec<u8>, Option<(usize, usize)>);

/// Build run ends bytes and values range directly for batch processing
fn build_extend_arrays<T: ArrowNativeType + std::ops::Add<Output = T> + CheckedAdd>(
buffer: &Buffer,
length: usize,
start: usize,
len: usize,
dest_last_run_end: T,
) -> Result<(Vec<u8>, Option<(usize, usize)>), ArrowError> {
) -> Result<ExtendArrays, ArrowError> {
let mut run_ends_bytes = Vec::new();
let mut values_range: Option<(usize, usize)> = None;
let end = start + len;
Expand All @@ -116,23 +119,27 @@ fn build_extend_arrays<T: ArrowNativeType + std::ops::Add<Output = T> + CheckedA
};
current_run_end = current_run_end
.checked_add(&T::usize_as(end_offset - start_offset))
.ok_or_else(|| ArrowError::InvalidArgumentError(
"run end overflow when extending RunEndEncoded array: \
.ok_or_else(|| {
ArrowError::InvalidArgumentError(
"run end overflow when extending RunEndEncoded array: \
use a larger run-end type (e.g. Int64 instead of Int32)"
.to_string(),
))?;
.to_string(),
)
})?;
run_ends_bytes.extend_from_slice(current_run_end.to_byte_slice());

// Start the range
values_range = Some((i, i + 1));
} else if prev_end >= start && run_end <= end {
current_run_end = current_run_end
.checked_add(&T::usize_as(run_end - prev_end))
.ok_or_else(|| ArrowError::InvalidArgumentError(
"run end overflow when extending RunEndEncoded array: \
.ok_or_else(|| {
ArrowError::InvalidArgumentError(
"run end overflow when extending RunEndEncoded array: \
use a larger run-end type (e.g. Int64 instead of Int32)"
.to_string(),
))?;
.to_string(),
)
})?;
run_ends_bytes.extend_from_slice(current_run_end.to_byte_slice());

// Extend the range
Expand All @@ -143,11 +150,13 @@ fn build_extend_arrays<T: ArrowNativeType + std::ops::Add<Output = T> + CheckedA
} else if prev_end < end && run_end >= end {
current_run_end = current_run_end
.checked_add(&T::usize_as(end - prev_end))
.ok_or_else(|| ArrowError::InvalidArgumentError(
"run end overflow when extending RunEndEncoded array: \
.ok_or_else(|| {
ArrowError::InvalidArgumentError(
"run end overflow when extending RunEndEncoded array: \
use a larger run-end type (e.g. Int64 instead of Int32)"
.to_string(),
))?;
.to_string(),
)
})?;
run_ends_bytes.extend_from_slice(current_run_end.to_byte_slice());

// Extend the range and break
Expand Down
15 changes: 5 additions & 10 deletions arrow-data/src/transform/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,16 @@ pub(super) fn build_extend(_: &ArrayData) -> Extend<'_> {
// Collect field names before the mutable borrow of child_data.
let field_names = struct_field_names(&mutable.data_type);
for (col_idx, child) in mutable.child_data.iter_mut().enumerate() {
child.try_extend(index, start, start + len).map_err(|e| {
wrap_column_error(e, col_idx, &field_names)
})?;
child
.try_extend(index, start, start + len)
.map_err(|e| wrap_column_error(e, col_idx, &field_names))?;
}
Ok(())
},
)
}

pub(super) fn extend_nulls(
mutable: &mut _MutableArrayData,
len: usize,
) -> Result<(), ArrowError> {
pub(super) fn extend_nulls(mutable: &mut _MutableArrayData, len: usize) -> Result<(), ArrowError> {
let field_names = struct_field_names(&mutable.data_type);
for (col_idx, child) in mutable.child_data.iter_mut().enumerate() {
child
Expand All @@ -60,7 +57,5 @@ fn wrap_column_error(e: ArrowError, col_idx: usize, field_names: &[String]) -> A
.get(col_idx)
.map(|n| format!(" (\"{n}\")"))
.unwrap_or_default();
ArrowError::InvalidArgumentError(format!(
"struct column {col_idx}{name_ctx} failed: {e}"
))
ArrowError::InvalidArgumentError(format!("struct column {col_idx}{name_ctx} failed: {e}"))
}