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

Method buffers

arrow-array/src/ffi.rs:417–464  ·  view source on GitHub ↗

returns all buffers, as organized by Rust (i.e. null buffer is skipped if it's present in the spec of the type)

(&self, can_contain_null_mask: bool, variadic: bool)

Source from the content-addressed store, hash-verified

415 /// returns all buffers, as organized by Rust (i.e. null buffer is skipped if it's present
416 /// in the spec of the type)
417 fn buffers(&self, can_contain_null_mask: bool, variadic: bool) -> Result<Vec<Buffer>> {
418 // + 1: skip null buffer
419 let buffer_begin = can_contain_null_mask as usize;
420 let buffer_end = self.array.num_buffers() - usize::from(variadic);
421
422 let variadic_buffer_lens = if variadic {
423 // Each views array has 1 (optional) null buffer, 1 views buffer, 1 lengths buffer.
424 // Rest are variadic.
425 let num_variadic_buffers =
426 self.array.num_buffers() - (2 + usize::from(can_contain_null_mask));
427 if num_variadic_buffers == 0 {
428 &[]
429 } else {
430 let lengths = self.array.buffer(self.array.num_buffers() - 1);
431 // SAFETY: is lengths is non-null, then it must be valid for up to num_variadic_buffers.
432 unsafe { std::slice::from_raw_parts(lengths.cast::<i64>(), num_variadic_buffers) }
433 }
434 } else {
435 &[]
436 };
437
438 (buffer_begin..buffer_end)
439 .map(|index| {
440 let len = self.buffer_len(index, variadic_buffer_lens, &self.data_type)?;
441 match unsafe { create_buffer(self.owner.clone(), self.array, index, len) } {
442 Some(buf) => {
443 // External libraries may use a dangling pointer for a buffer with length 0.
444 // We respect the array length specified in the C Data Interface. Actually,
445 // if the length is incorrect, we cannot create a correct buffer even if
446 // the pointer is valid.
447 if buf.is_empty() {
448 Ok(MutableBuffer::new(0).into())
449 } else {
450 Ok(buf)
451 }
452 }
453 None if len == 0 => {
454 // Null data buffer, which Rust doesn't allow. So create
455 // an empty buffer.
456 Ok(MutableBuffer::new(0).into())
457 }
458 None => Err(ArrowError::CDataInterface(format!(
459 "The external buffer at position {index} is null."
460 ))),
461 }
462 })
463 .collect()
464 }
465
466 /// Returns the length, in bytes, of the buffer `i` (indexed according to the C data interface)
467 /// Rust implementation uses fixed-sized buffers, which require knowledge of their `len`.

Callers 15

consumeMethod · 0.45
fromMethod · 0.45
into_builderMethod · 0.45
fromMethod · 0.45
fromMethod · 0.45
fromMethod · 0.45
fromMethod · 0.45
test_custom_type_idsFunction · 0.45
test_empty_offsetsFunction · 0.45
fromMethod · 0.45

Calls 7

num_buffersMethod · 0.80
collectMethod · 0.80
buffer_lenMethod · 0.80
create_bufferFunction · 0.70
bufferMethod · 0.45
cloneMethod · 0.45
is_emptyMethod · 0.45

Tested by 6

test_custom_type_idsFunction · 0.36
test_empty_offsetsFunction · 0.36
test_empty_offsetsFunction · 0.36
test_empty_offsetsFunction · 0.36
test_empty_offsetsFunction · 0.36