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

Method check_bounds

arrow-data/src/data.rs:1592–1624  ·  view source on GitHub ↗

Validates that each value in self.buffers (typed as T) is within the range [0, max_value], inclusive

(&self, max_value: i64)

Source from the content-addressed store, hash-verified

1590 /// Validates that each value in self.buffers (typed as T)
1591 /// is within the range [0, max_value], inclusive
1592 fn check_bounds<T>(&self, max_value: i64) -> Result<(), ArrowError>
1593 where
1594 T: ArrowNativeType + TryInto<i64> + num_traits::Num + std::fmt::Display,
1595 {
1596 let required_len = checked_len_plus_offset(&self.data_type, self.len, self.offset)?;
1597 let buffer = &self.buffers[0];
1598
1599 // This should have been checked as part of `validate()` prior
1600 // to calling `validate_full()` but double check to be sure
1601 assert!(buffer.len() / mem::size_of::<T>() >= required_len);
1602
1603 // Justification: buffer size was validated above
1604 let indexes: &[T] = &buffer.typed_data::<T>()[self.offset..required_len];
1605
1606 indexes.iter().enumerate().try_for_each(|(i, &dict_index)| {
1607 // Do not check the value is null (value can be arbitrary)
1608 if self.is_null(i) {
1609 return Ok(());
1610 }
1611 let dict_index: i64 = dict_index.try_into().map_err(|_| {
1612 ArrowError::InvalidArgumentError(format!(
1613 "Value at position {i} out of bounds: {dict_index} (can not convert to i64)"
1614 ))
1615 })?;
1616
1617 if dict_index < 0 || dict_index > max_value {
1618 return Err(ArrowError::InvalidArgumentError(format!(
1619 "Value at position {i} out of bounds: {dict_index} (should be in [0, {max_value}])"
1620 )));
1621 }
1622 Ok(())
1623 })
1624 }
1625
1626 /// Validates that each value in run_ends array is positive and strictly increasing.
1627 fn check_run_ends<T>(&self) -> Result<(), ArrowError>

Callers

nothing calls this directly

Calls 3

checked_len_plus_offsetFunction · 0.85
iterMethod · 0.45
is_nullMethod · 0.45

Tested by

no test coverage detected