Struct arrow::array::MutableArrayData
source · [−]pub struct MutableArrayData<'a> { /* private fields */ }
Expand description
Struct to efficiently and interactively create an ArrayData from an existing ArrayData by
copying chunks.
The main use case of this struct is to perform unary operations to arrays of arbitrary types, such as filter
and take
.
Example:
use arrow::{array::{Int32Array, Array, MutableArrayData}};
let array = Int32Array::from(vec![1, 2, 3, 4, 5]);
let array = array.data();
// Create a new `MutableArrayData` from an array and with a capacity of 4.
// Capacity here is equivalent to `Vec::with_capacity`
let arrays = vec![array];
let mut mutable = MutableArrayData::new(arrays, false, 4);
mutable.extend(0, 1, 3); // extend from the slice [1..3], [2,3]
mutable.extend(0, 0, 3); // extend from the slice [0..3], [1,2,3]
// `.freeze()` to convert `MutableArrayData` into a `ArrayData`.
let new_array = Int32Array::from(mutable.freeze());
assert_eq!(Int32Array::from(vec![2, 3, 1, 2, 3]), new_array);
Implementations
sourceimpl<'a> MutableArrayData<'a>
impl<'a> MutableArrayData<'a>
sourcepub fn new(arrays: Vec<&'a ArrayData>, use_nulls: bool, capacity: usize) -> Self
pub fn new(arrays: Vec<&'a ArrayData>, use_nulls: bool, capacity: usize) -> Self
returns a new MutableArrayData with capacity to capacity
slots and specialized to create an
ArrayData from multiple arrays
.
use_nulls
is a flag used to optimize insertions. It should be false
if the only source of nulls
are the arrays themselves and true
if the user plans to call MutableArrayData::extend_nulls.
In other words, if use_nulls
is false
, calling MutableArrayData::extend_nulls should not be used.
sourcepub fn with_capacities(
arrays: Vec<&'a ArrayData>,
use_nulls: bool,
capacities: Capacities
) -> Self
pub fn with_capacities(
arrays: Vec<&'a ArrayData>,
use_nulls: bool,
capacities: Capacities
) -> Self
Similar to MutableArrayData::new, but lets users define the preallocated capacities of the array. See also MutableArrayData::new for more information on the arguments.
Panic
This function panics if the given capacities
don’t match the data type of arrays
. Or when
a Capacities variant is not yet supported.
sourcepub fn extend(&mut self, index: usize, start: usize, end: usize)
pub fn extend(&mut self, index: usize, start: usize, end: usize)
Extends this array with a chunk of its source arrays
Arguments
index
- the index of array that you what to copy values fromstart
- the start index of the chunk (inclusive)end
- the end index of the chunk (exclusive)
Panic
This function panics if there is an invalid index,
i.e. index
>= the number of source arrays
or end
> the length of the index
th array
sourcepub fn extend_nulls(&mut self, len: usize)
pub fn extend_nulls(&mut self, len: usize)
Extends this MutableArrayData with null elements, disregarding the bound arrays
sourcepub fn null_count(&self) -> usize
pub fn null_count(&self) -> usize
Returns the current null count
sourcepub fn freeze(self) -> ArrayData
pub fn freeze(self) -> ArrayData
Creates a ArrayData from the pushed regions up to this point, consuming self
.
sourcepub fn into_builder(self) -> ArrayDataBuilder
pub fn into_builder(self) -> ArrayDataBuilder
Creates a ArrayDataBuilder from the pushed regions up to this point, consuming self
.
This is useful for extending the default behavior of MutableArrayData.
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for MutableArrayData<'a>
impl<'a> !Send for MutableArrayData<'a>
impl<'a> !Sync for MutableArrayData<'a>
impl<'a> Unpin for MutableArrayData<'a>
impl<'a> !UnwindSafe for MutableArrayData<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more