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

Method try_into_binary

arrow-row/src/lib.rs:1350–1368  ·  view source on GitHub ↗

Create a [BinaryArray] from the [Rows] data without reallocating the underlying bytes. ``` # use std::sync::Arc; # use std::collections::HashSet; # use arrow_array::cast::AsArray; # use arrow_array::StringArray; # use arrow_row::{OwnedRow, Row, RowConverter, RowParser, SortField}; # use arrow_schema::DataType; # let converter = RowConverter::new(vec![SortField::new(DataType::Utf8)]).unwrap(); le

(self)

Source from the content-addressed store, hash-verified

1348 /// This function will return an error if there is more data than can be stored in
1349 /// a [BinaryArray] -- i.e. if the total data size is more than 2GiB.
1350 pub fn try_into_binary(self) -> Result<BinaryArray, ArrowError> {
1351 if self.buffer.len() > i32::MAX as usize {
1352 return Err(ArrowError::InvalidArgumentError(format!(
1353 "{}-byte rows buffer too long to convert into a i32-indexed BinaryArray",
1354 self.buffer.len()
1355 )));
1356 }
1357 // We've checked that the buffer length fits in an i32; so all offsets into that buffer should fit as well.
1358 let offsets_scalar = ScalarBuffer::from_iter(self.offsets.into_iter().map(i32::usize_as));
1359 // SAFETY: offsets buffer is nonempty, monotonically increasing, and all represent valid indexes into buffer.
1360 let array = unsafe {
1361 BinaryArray::new_unchecked(
1362 OffsetBuffer::new_unchecked(offsets_scalar),
1363 Buffer::from_vec(self.buffer),
1364 None,
1365 )
1366 };
1367 Ok(array)
1368 }
1369}
1370
1371impl<'a> IntoIterator for &'a Rows {

Callers 4

test_invalid_utf8_arrayFunction · 0.80
fuzz_testFunction · 0.80
get_values_buffer_lenFunction · 0.80

Calls 3

from_iterFunction · 0.50
lenMethod · 0.45
into_iterMethod · 0.45

Tested by 2

test_invalid_utf8_arrayFunction · 0.64