Struct arrow::array::PrimitiveArray

source ·
pub struct PrimitiveArray<T>where
    T: ArrowPrimitiveType,
{ /* private fields */ }
Expand description

Array whose elements are of primitive types.

Example: From an iterator of values

use arrow_array::{Array, PrimitiveArray, types::Int32Type};
let arr: PrimitiveArray<Int32Type> = PrimitiveArray::from_iter_values((0..10).map(|x| x + 1));
assert_eq!(10, arr.len());
assert_eq!(0, arr.null_count());
for i in 0..10i32 {
    assert_eq!(i + 1, arr.value(i as usize));
}

Implementations§

Returns the length of this array.

Returns whether this array is empty.

Returns a slice of the values of this array

Returns a new primitive array builder

Returns the primitive value at index i.

Safety

caller must ensure that the passed in offset is less than the array len()

Returns the primitive value at index i.

Panics

Panics if index i is out of bounds

Creates a PrimitiveArray based on an iterator of values without nulls

Creates a PrimitiveArray based on a constant value with count elements

Returns an iterator that returns the values of array.value(i) for an iterator with each element i

Returns an iterator that returns the values of array.value(i) for an iterator with each element i

Safety

caller must ensure that the offsets in the iterator are less than the array len()

Reinterprets this array’s contents as a different data type without copying

This can be used to efficiently convert between primitive arrays with the same underlying representation

Note: this will not modify the underlying values, and therefore may change the semantic values of the array, e.g. 100 milliseconds in a TimestampNanosecondArray will become 100 seconds in a TimestampSecondArray.

For casts that preserve the semantic value, check out the [compute kernels]

compute kernels

let a = Int64Array::from_iter_values([1, 2, 3, 4]);
let b: TimestampNanosecondArray = a.reinterpret_cast();

Applies an unary and infallible function to a primitive array. This is the fastest way to perform an operation on a primitive array when the benefits of a vectorized operation outweigh the cost of branching nulls and non-nulls.

Implementation

This will apply the function for all values, including those on null slots. This implies that the operation must be infallible for any value of the corresponding type or this function may panic.

Example
let array = Int32Array::from(vec![Some(5), Some(7), None]);
let c = array.unary(|x| x * 2 + 1);
assert_eq!(c, Int32Array::from(vec![Some(11), Some(15), None]));

Applies an unary and infallible function to a mutable primitive array. Mutable primitive array means that the buffer is not shared with other arrays. As a result, this mutates the buffer directly without allocating new buffer.

Implementation

This will apply the function for all values, including those on null slots. This implies that the operation must be infallible for any value of the corresponding type or this function may panic.

Example
let array = Int32Array::from(vec![Some(5), Some(7), None]);
let c = array.unary_mut(|x| x * 2 + 1).unwrap();
assert_eq!(c, Int32Array::from(vec![Some(11), Some(15), None]));

Applies a unary and fallible function to all valid values in a primitive array

This is unlike Self::unary which will apply an infallible function to all rows regardless of validity, in many cases this will be significantly faster and should be preferred if op is infallible.

Note: LLVM is currently unable to effectively vectorize fallible operations

Applies a unary and nullable function to all valid values in a primitive array

This is unlike Self::unary which will apply an infallible function to all rows regardless of validity, in many cases this will be significantly faster and should be preferred if op is infallible.

Note: LLVM is currently unable to effectively vectorize fallible operations

Returns PrimitiveBuilder of this primitive array for mutating its values if the underlying data buffer is not shared by others.

Returns value as a chrono NaiveDateTime, handling time resolution

If a data type cannot be converted to NaiveDateTime, a None is returned. A valid value is expected, thus the user should first check for validity.

Returns value as a chrono NaiveDateTime, handling time resolution with the provided tz

functionally it is same as value_as_datetime, however it adds the passed tz to the to-be-returned NaiveDateTime

Returns value as a chrono NaiveDate by using Self::datetime()

If a data type cannot be converted to NaiveDate, a None is returned

Returns a value as a chrono NaiveTime

Date32 and Date64 return UTC midnight as they do not have time resolution

Returns a value as a chrono Duration

If a data type cannot be converted to Duration, a None is returned

constructs a new iterator

Creates a PrimitiveArray from an iterator of trusted length.

Safety

The iterator must be TrustedLen. I.e. that size_hint().1 correctly reports its length.

👎Deprecated: Use with_timezone_opt instead

Construct a timestamp array from a vec of i64 values and an optional timezone

👎Deprecated: Use with_timezone_opt instead

Construct a timestamp array from a vec of Option<i64> values and an optional timezone

Construct a timestamp array with new timezone

Construct a timestamp array with UTC

Construct a timestamp array with an optional timezone

Returns a Decimal array with the same data as self, with the specified precision and scale.

Returns an Error if:

  • precision is zero
  • precision is larger than T:MAX_PRECISION
  • scale is larger than T::MAX_SCALE
  • scale is > precision

Validates values in this array can be properly interpreted with the specified precision.

Returns Self::value formatted as a string

Returns the decimal precision of this array

Returns the decimal scale of this array

Trait Implementations§

Returns the array as Any so that it can be downcasted to a specific implementation. Read more
Returns a reference to the underlying data of this array.
Returns the underlying data of this array.
Returns a reference-counted pointer to the underlying data of this array.
Returns a reference to the DataType of this array. Read more
Returns a zero-copy slice of this array with the indicated offset and length. Read more
Returns the length (i.e., number of elements) of this array. Read more
Returns whether this array is empty. Read more
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
Returns whether the element at index is null. When using this function on a slice, the index is relative to the slice. Read more
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
Returns the total number of null values in this array. Read more
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
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
The Arrow type of the element being accessed.
Returns the element at index i Read more
Returns the element at index i Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Constructs a PrimitiveArray from an array data reference.

Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Creates a value from an iterator. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.