Struct arrow::array::DecimalArray
source · [−]pub struct DecimalArray { /* private fields */ }
Expand description
DecimalArray
stores fixed width decimal numbers,
with a fixed precision and scale.
Examples
use arrow::array::{Array, DecimalArray};
use arrow::datatypes::DataType;
// Create a DecimalArray with the default precision and scale
let decimal_array: DecimalArray = vec![
Some(8_887_000_000),
None,
Some(-8_887_000_000),
]
.into_iter().collect();
// set precision and scale so values are interpreted
// as `8887.000000`, `Null`, and `-8887.000000`
let decimal_array = decimal_array
.with_precision_and_scale(23, 6)
.unwrap();
assert_eq!(&DataType::Decimal(23, 6), decimal_array.data_type());
assert_eq!(8_887_000_000, decimal_array.value(0));
assert_eq!("8887.000000", decimal_array.value_as_string(0));
assert_eq!(3, decimal_array.len());
assert_eq!(1, decimal_array.null_count());
assert_eq!(32, decimal_array.value_offset(2));
assert_eq!(16, decimal_array.value_length());
assert_eq!(23, decimal_array.precision());
assert_eq!(6, decimal_array.scale());
Implementations
sourceimpl DecimalArray
impl DecimalArray
sourcepub fn value_offset(&self, i: usize) -> i32
pub fn value_offset(&self, i: usize) -> i32
Returns the offset for the element at index i
.
Note this doesn’t do any bound checking, for performance reason.
sourcepub fn value_length(&self) -> i32
pub fn value_length(&self) -> i32
Returns the length for an element.
All elements have the same length as the array is a fixed size.
sourcepub fn value_data(&self) -> Buffer
pub fn value_data(&self) -> Buffer
Returns a clone of the value data buffer
pub fn value_as_string(&self, row: usize) -> String
pub fn from_fixed_size_list_array(
v: FixedSizeListArray,
precision: usize,
scale: usize
) -> Self
sourcepub fn from_iter_values<I: IntoIterator<Item = i128>>(iter: I) -> Self
pub fn from_iter_values<I: IntoIterator<Item = i128>>(iter: I) -> Self
Creates a DecimalArray with default precision and scale,
based on an iterator of i128
values without nulls
sourcepub fn precision(&self) -> usize
pub fn precision(&self) -> usize
Return the precision (total digits) that can be stored by this array
sourcepub fn scale(&self) -> usize
pub fn scale(&self) -> usize
Return the scale (digits after the decimal) that can be stored by this array
sourcepub fn with_precision_and_scale(
self,
precision: usize,
scale: usize
) -> Result<Self>
pub fn with_precision_and_scale(
self,
precision: usize,
scale: usize
) -> Result<Self>
Returns a DecimalArray with the same data as self, with the specified precision.
Returns an Error if:
precision
is larger thanDECIMAL_MAX_PRECISION
scale
is larger thanDECIMAL_MAX_SCALE
;scale
is >precision
sourcepub fn default_type() -> DataType
pub fn default_type() -> DataType
The default precision and scale used when not specified.
sourceimpl<'a> DecimalArray
impl<'a> DecimalArray
sourcepub fn iter(&'a self) -> DecimalIter<'a>ⓘNotable traits for DecimalIter<'a>impl<'a> Iterator for DecimalIter<'a> type Item = Option<i128>;
pub fn iter(&'a self) -> DecimalIter<'a>ⓘNotable traits for DecimalIter<'a>impl<'a> Iterator for DecimalIter<'a> type Item = Option<i128>;
constructs a new iterator
Trait Implementations
sourceimpl Array for DecimalArray
impl Array for DecimalArray
sourcefn data_ref(&self) -> &ArrayData
fn data_ref(&self) -> &ArrayData
Returns a reference-counted pointer to the underlying data of this array.
sourcefn slice(&self, offset: usize, length: usize) -> ArrayRef
fn slice(&self, offset: usize, length: usize) -> ArrayRef
Returns a zero-copy slice of this array with the indicated offset and length. Read more
sourcefn offset(&self) -> usize
fn offset(&self) -> usize
Returns the offset into the underlying data used by this array(-slice).
Note that the underlying data can be shared by many arrays.
This defaults to 0
. Read more
sourcefn is_null(&self, index: usize) -> bool
fn is_null(&self, index: usize) -> bool
Returns whether the element at index
is null.
When using this function on a slice, the index is relative to the slice. Read more
sourcefn is_valid(&self, index: usize) -> bool
fn is_valid(&self, index: usize) -> bool
Returns whether the element at index
is not null.
When using this function on a slice, the index is relative to the slice. Read more
sourcefn null_count(&self) -> usize
fn null_count(&self) -> usize
Returns the total number of null values in this array. Read more
sourcefn get_buffer_memory_size(&self) -> usize
fn get_buffer_memory_size(&self) -> usize
Returns the total number of bytes of memory pointed to by this array. The buffers store bytes in the Arrow memory format, and include the data as well as the validity map. Read more
sourcefn get_array_memory_size(&self) -> usize
fn get_array_memory_size(&self) -> usize
Returns the total number of bytes of memory occupied physically by this array.
This value will always be greater than returned by get_buffer_memory_size()
and
includes the overhead of the data structures that contain the pointers to the various buffers. Read more
sourcefn to_raw(&self) -> Result<(*const FFI_ArrowArray, *const FFI_ArrowSchema)>
fn to_raw(&self) -> Result<(*const FFI_ArrowArray, *const FFI_ArrowSchema)>
returns two pointers that represent this array in the C Data Interface (FFI)
sourceimpl Debug for DecimalArray
impl Debug for DecimalArray
sourceimpl From<ArrayData> for DecimalArray
impl From<ArrayData> for DecimalArray
sourceimpl From<DecimalArray> for ArrayData
impl From<DecimalArray> for ArrayData
sourcefn from(array: DecimalArray) -> Self
fn from(array: DecimalArray) -> Self
Converts to this type from the input type.
sourceimpl<Ptr: Borrow<Option<i128>>> FromIterator<Ptr> for DecimalArray
impl<Ptr: Borrow<Option<i128>>> FromIterator<Ptr> for DecimalArray
sourcefn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl<'a> IntoIterator for &'a DecimalArray
impl<'a> IntoIterator for &'a DecimalArray
sourceimpl JsonEqual for DecimalArray
impl JsonEqual for DecimalArray
sourceimpl PartialEq<DecimalArray> for DecimalArray
impl PartialEq<DecimalArray> for DecimalArray
sourceimpl PartialEq<DecimalArray> for Value
impl PartialEq<DecimalArray> for Value
Auto Trait Implementations
impl RefUnwindSafe for DecimalArray
impl Send for DecimalArray
impl Sync for DecimalArray
impl Unpin for DecimalArray
impl UnwindSafe for DecimalArray
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