MCPcopy Create free account
hub / github.com/apache/arrow-rs / check_run_ends

Method check_run_ends

arrow-data/src/data.rs:1627–1662  ·  view source on GitHub ↗

Validates that each value in run_ends array is positive and strictly increasing.

(&self)

Source from the content-addressed store, hash-verified

1625
1626 /// Validates that each value in run_ends array is positive and strictly increasing.
1627 fn check_run_ends<T>(&self) -> Result<(), ArrowError>
1628 where
1629 T: ArrowNativeType + TryInto<i64> + num_traits::Num + std::fmt::Display,
1630 {
1631 let values = self.typed_buffer::<T>(0, self.len)?;
1632 let mut prev_value: i64 = 0_i64;
1633 values.iter().enumerate().try_for_each(|(ix, &inp_value)| {
1634 let value: i64 = inp_value.try_into().map_err(|_| {
1635 ArrowError::InvalidArgumentError(format!(
1636 "Value at position {ix} out of bounds: {inp_value} (can not convert to i64)"
1637 ))
1638 })?;
1639 if value <= 0_i64 {
1640 return Err(ArrowError::InvalidArgumentError(format!(
1641 "The values in run_ends array should be strictly positive. Found value {value} at index {ix} that does not match the criteria."
1642 )));
1643 }
1644 if ix > 0 && value <= prev_value {
1645 return Err(ArrowError::InvalidArgumentError(format!(
1646 "The values in run_ends array should be strictly increasing. Found value {value} at index {ix} with previous value {prev_value} that does not match the criteria."
1647 )));
1648 }
1649
1650 prev_value = value;
1651 Ok(())
1652 })?;
1653
1654 let len_plus_offset = checked_len_plus_offset(&self.data_type, self.len, self.offset)?;
1655 if prev_value.as_usize() < len_plus_offset {
1656 return Err(ArrowError::InvalidArgumentError(format!(
1657 "The offset + length of array should be less or equal to last value in the run_ends array. The last value of run_ends array is {prev_value} and offset + length of array is {}.",
1658 len_plus_offset
1659 )));
1660 }
1661 Ok(())
1662 }
1663
1664 /// Returns true if this `ArrayData` is equal to `other`, using pointer comparisons
1665 /// to determine buffer equality. This is cheaper than `PartialEq::eq` but may

Callers

nothing calls this directly

Calls 3

checked_len_plus_offsetFunction · 0.85
as_usizeMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected