Create a new ArrayData, validating that the provided buffers form a valid Arrow array of the specified data type. If the number of nulls in `null_bit_buffer` is 0 then the null_bit_buffer is set to `None`. Internally this calls through to [`Self::validate_data`] Note: This is a low level API and most users of the arrow crate should create arrays using the builders found in [arrow_array](https:/
(
data_type: DataType,
len: usize,
null_bit_buffer: Option<Buffer>,
offset: usize,
buffers: Vec<Buffer>,
child_data: Vec<ArrayData>,
)
| 328 | /// |
| 329 | /// See also [`Self::into_parts`] to recover the fields |
| 330 | pub fn try_new( |
| 331 | data_type: DataType, |
| 332 | len: usize, |
| 333 | null_bit_buffer: Option<Buffer>, |
| 334 | offset: usize, |
| 335 | buffers: Vec<Buffer>, |
| 336 | child_data: Vec<ArrayData>, |
| 337 | ) -> Result<Self, ArrowError> { |
| 338 | // we must check the length of `null_bit_buffer` first |
| 339 | // because we use this buffer to calculate `null_count` |
| 340 | // in `Self::new_unchecked`. |
| 341 | if let Some(null_bit_buffer) = null_bit_buffer.as_ref() { |
| 342 | let len_plus_offset = checked_len_plus_offset(&data_type, len, offset)?; |
| 343 | let needed_len = bit_util::ceil(len_plus_offset, 8); |
| 344 | if null_bit_buffer.len() < needed_len { |
| 345 | return Err(ArrowError::InvalidArgumentError(format!( |
| 346 | "null_bit_buffer size too small. got {} needed {}", |
| 347 | null_bit_buffer.len(), |
| 348 | needed_len |
| 349 | ))); |
| 350 | } |
| 351 | } |
| 352 | // Safety justification: `validate_full` is called below |
| 353 | let new_self = unsafe { |
| 354 | Self::new_unchecked( |
| 355 | data_type, |
| 356 | len, |
| 357 | None, |
| 358 | null_bit_buffer, |
| 359 | offset, |
| 360 | buffers, |
| 361 | child_data, |
| 362 | ) |
| 363 | }; |
| 364 | |
| 365 | // As the data is not trusted, do a full validation of its contents |
| 366 | // We don't need to validate children as we can assume that the |
| 367 | // [`ArrayData`] in `child_data` have already been validated through |
| 368 | // a call to `ArrayData::try_new` or created using unsafe |
| 369 | new_self.validate_data()?; |
| 370 | Ok(new_self) |
| 371 | } |
| 372 | |
| 373 | /// Return the constituent parts of this ArrayData |
| 374 | /// |
nothing calls this directly
no test coverage detected