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

Function write_array_data

arrow-ipc/src/writer.rs:1807–2102  ·  view source on GitHub ↗
(
    array_data: &ArrayData,
    buffers: &mut Vec<crate::Buffer>,
    arrow_data: &mut Vec<u8>,
    nodes: &mut Vec<crate::FieldNode>,
    offset: i64,
    num_rows: usize,
    null_count: usize,
  

Source from the content-addressed store, hash-verified

1805/// Write array data to a vector of bytes
1806#[allow(clippy::too_many_arguments)]
1807fn write_array_data(
1808 array_data: &ArrayData,
1809 buffers: &mut Vec<crate::Buffer>,
1810 arrow_data: &mut Vec<u8>,
1811 nodes: &mut Vec<crate::FieldNode>,
1812 offset: i64,
1813 num_rows: usize,
1814 null_count: usize,
1815 compression_codec: Option<CompressionCodec>,
1816 compression_context: &mut CompressionContext,
1817 write_options: &IpcWriteOptions,
1818) -> Result<i64, ArrowError> {
1819 let mut offset = offset;
1820 if !matches!(array_data.data_type(), DataType::Null) {
1821 nodes.push(crate::FieldNode::new(num_rows as i64, null_count as i64));
1822 } else {
1823 // NullArray's null_count equals to len, but the `null_count` passed in is from ArrayData
1824 // where null_count is always 0.
1825 nodes.push(crate::FieldNode::new(num_rows as i64, num_rows as i64));
1826 }
1827 if has_validity_bitmap(array_data.data_type(), write_options) {
1828 // write null buffer if exists
1829 let null_buffer = match array_data.nulls() {
1830 None => {
1831 // create a buffer and fill it with valid bits
1832 let num_bytes = bit_util::ceil(num_rows, 8);
1833 let buffer = MutableBuffer::new(num_bytes);
1834 let buffer = buffer.with_bitset(num_bytes, true);
1835 buffer.into()
1836 }
1837 Some(buffer) => buffer.inner().sliced(),
1838 };
1839
1840 offset = write_buffer(
1841 null_buffer.as_slice(),
1842 buffers,
1843 arrow_data,
1844 offset,
1845 compression_codec,
1846 compression_context,
1847 write_options.alignment,
1848 )?;
1849 }
1850
1851 let data_type = array_data.data_type();
1852 if matches!(data_type, DataType::Binary | DataType::Utf8) {
1853 let (offsets, values) = get_byte_array_buffers::<i32>(array_data);
1854 for buffer in [offsets, values] {
1855 offset = write_buffer(
1856 buffer.as_slice(),
1857 buffers,
1858 arrow_data,
1859 offset,
1860 compression_codec,
1861 compression_context,
1862 write_options.alignment,
1863 )?;
1864 }

Callers 2

record_batch_to_bytesMethod · 0.85

Calls 15

has_validity_bitmapFunction · 0.85
write_bufferFunction · 0.85
get_or_truncate_bufferFunction · 0.85
unslice_run_arrayFunction · 0.85
with_bitsetMethod · 0.80
slicedMethod · 0.80
bit_sliceMethod · 0.80
child_dataMethod · 0.80
ceilFunction · 0.50
pushMethod · 0.45
data_typeMethod · 0.45
nullsMethod · 0.45

Tested by

no test coverage detected