@@ -231,6 +231,7 @@ pub struct ArrayData {
231231 nulls : Option < NullBuffer > ,
232232}
233233
234+ /// A thread-safe, shared reference to the Arrow array data.
234235pub type ArrayDataRef = Arc < ArrayData > ;
235236
236237impl ArrayData {
@@ -1747,7 +1748,12 @@ pub enum BufferSpec {
17471748 /// for array slicing and interoperability with `Vec`, which cannot be over-aligned.
17481749 ///
17491750 /// Note that these alignment requirements will vary between architectures
1750- FixedWidth { byte_width : usize , alignment : usize } ,
1751+ FixedWidth {
1752+ /// The width of each element in bytes
1753+ byte_width : usize ,
1754+ /// The alignment required by Rust for an array of the corresponding primitive
1755+ alignment : usize ,
1756+ } ,
17511757 /// Variable width, such as string data for utf8 data
17521758 VariableWidth ,
17531759 /// Buffer holds a bitmap.
@@ -1783,6 +1789,7 @@ pub struct ArrayDataBuilder {
17831789
17841790impl ArrayDataBuilder {
17851791 #[ inline]
1792+ /// Creates a new array data builder
17861793 pub const fn new ( data_type : DataType ) -> Self {
17871794 Self {
17881795 data_type,
@@ -1796,61 +1803,72 @@ impl ArrayDataBuilder {
17961803 }
17971804 }
17981805
1806+ /// Creates a new array data builder from an existing one, changing the data type
17991807 pub fn data_type ( self , data_type : DataType ) -> Self {
18001808 Self { data_type, ..self }
18011809 }
18021810
18031811 #[ inline]
18041812 #[ allow( clippy:: len_without_is_empty) ]
1813+ /// Sets the length of the [ArrayData]
18051814 pub const fn len ( mut self , n : usize ) -> Self {
18061815 self . len = n;
18071816 self
18081817 }
18091818
1819+ /// Sets the null buffer of the [ArrayData]
18101820 pub fn nulls ( mut self , nulls : Option < NullBuffer > ) -> Self {
18111821 self . nulls = nulls;
18121822 self . null_count = None ;
18131823 self . null_bit_buffer = None ;
18141824 self
18151825 }
18161826
1827+ /// Sets the null count of the [ArrayData]
18171828 pub fn null_count ( mut self , null_count : usize ) -> Self {
18181829 self . null_count = Some ( null_count) ;
18191830 self
18201831 }
18211832
1833+ /// Sets the `null_bit_buffer` of the [ArrayData]
18221834 pub fn null_bit_buffer ( mut self , buf : Option < Buffer > ) -> Self {
18231835 self . nulls = None ;
18241836 self . null_bit_buffer = buf;
18251837 self
18261838 }
18271839
1840+ /// Sets the offset of the [ArrayData]
18281841 #[ inline]
18291842 pub const fn offset ( mut self , n : usize ) -> Self {
18301843 self . offset = n;
18311844 self
18321845 }
18331846
1847+ /// Sets the buffers of the [ArrayData]
18341848 pub fn buffers ( mut self , v : Vec < Buffer > ) -> Self {
18351849 self . buffers = v;
18361850 self
18371851 }
18381852
1853+ /// Adds a single buffer to the [ArrayData]'s buffers
18391854 pub fn add_buffer ( mut self , b : Buffer ) -> Self {
18401855 self . buffers . push ( b) ;
18411856 self
18421857 }
18431858
1844- pub fn add_buffers ( mut self , bs : Vec < Buffer > ) -> Self {
1859+ /// Adds multiple buffers to the [ArrayData]'s buffers
1860+ pub fn add_buffers < I : IntoIterator < Item = Buffer > > ( mut self , bs : I ) -> Self {
18451861 self . buffers . extend ( bs) ;
18461862 self
18471863 }
18481864
1865+ /// Sets the child data of the [ArrayData]
18491866 pub fn child_data ( mut self , v : Vec < ArrayData > ) -> Self {
18501867 self . child_data = v;
18511868 self
18521869 }
18531870
1871+ /// Adds a single child data to the [ArrayData]'s child data
18541872 pub fn add_child_data ( mut self , r : ArrayData ) -> Self {
18551873 self . child_data . push ( r) ;
18561874 self
@@ -1873,22 +1891,25 @@ impl ArrayDataBuilder {
18731891
18741892 /// Same as [`Self::build_unchecked`] but ignoring `force_validate` feature flag
18751893 unsafe fn build_impl ( self ) -> ArrayData {
1876- let nulls = self . nulls . or_else ( || {
1877- let buffer = self . null_bit_buffer ?;
1878- let buffer = BooleanBuffer :: new ( buffer, self . offset , self . len ) ;
1879- Some ( match self . null_count {
1880- Some ( n) => NullBuffer :: new_unchecked ( buffer, n) ,
1881- None => NullBuffer :: new ( buffer) ,
1894+ let nulls = self
1895+ . nulls
1896+ . or_else ( || {
1897+ let buffer = self . null_bit_buffer ?;
1898+ let buffer = BooleanBuffer :: new ( buffer, self . offset , self . len ) ;
1899+ Some ( match self . null_count {
1900+ Some ( n) => NullBuffer :: new_unchecked ( buffer, n) ,
1901+ None => NullBuffer :: new ( buffer) ,
1902+ } )
18821903 } )
1883- } ) ;
1904+ . filter ( |b| b . null_count ( ) != 0 ) ;
18841905
18851906 ArrayData {
18861907 data_type : self . data_type ,
18871908 len : self . len ,
18881909 offset : self . offset ,
18891910 buffers : self . buffers ,
18901911 child_data : self . child_data ,
1891- nulls : nulls . filter ( |b| b . null_count ( ) != 0 ) ,
1912+ nulls,
18921913 }
18931914 }
18941915
0 commit comments