pub enum ColumnarValue {
Array(ArrayRef),
Scalar(ScalarValue),
}Expand description
The result of evaluating an expression.
ColumnarValue::Scalar represents a single value repeated any number of
times. This is an important performance optimization for handling values
that do not change across rows.
ColumnarValue::Array represents a column of data, stored as an Arrow
ArrayRef
A slice of ColumnarValues logically represents a table, with each column
having the same number of rows. This means that all Arrays are the same
length.
§Example
A ColumnarValue::Array with an array of 5 elements and a
ColumnarValue::Scalar with the value 100
┌──────────────┐
│ ┌──────────┐ │
│ │ "A" │ │
│ ├──────────┤ │
│ │ "B" │ │
│ ├──────────┤ │
│ │ "C" │ │
│ ├──────────┤ │
│ │ "D" │ │ ┌──────────────┐
│ ├──────────┤ │ │ ┌──────────┐ │
│ │ "E" │ │ │ │ 100 │ │
│ └──────────┘ │ │ └──────────┘ │
└──────────────┘ └──────────────┘
ColumnarValue:: ColumnarValue::
Array ScalarLogically represents the following table:
| Column 1 | Column 2 |
|---|---|
| A | 100 |
| B | 100 |
| C | 100 |
| D | 100 |
| E | 100 |
§Performance Notes
When implementing functions or operators, it is important to consider the performance implications of handling scalar values.
Because all functions must handle ArrayRef, it is
convenient to convert ColumnarValue::Scalars using
Self::into_array. For example, ColumnarValue::values_to_arrays
converts multiple columnar values into arrays of the same length.
However, it is often much more performant to provide a different, implementation that handles scalar values differently
Variants§
Implementations§
Source§impl ColumnarValue
impl ColumnarValue
pub fn data_type(&self) -> DataType
Sourcepub fn into_array(self, num_rows: usize) -> Result<ArrayRef>
pub fn into_array(self, num_rows: usize) -> Result<ArrayRef>
Convert a columnar value into an Arrow ArrayRef with the specified
number of rows. Self::Scalar is converted by repeating the same
scalar multiple times which is not as efficient as handling the scalar
directly.
See Self::values_to_arrays to convert multiple columnar values into
arrays of the same length.
§Errors
Errors if self is a Scalar that fails to be converted into an array of size
Sourcepub fn to_array(&self, num_rows: usize) -> Result<ArrayRef>
pub fn to_array(&self, num_rows: usize) -> Result<ArrayRef>
Convert a columnar value into an Arrow ArrayRef with the specified
number of rows. Self::Scalar is converted by repeating the same
scalar multiple times which is not as efficient as handling the scalar
directly.
See Self::values_to_arrays to convert multiple columnar values into
arrays of the same length.
§Errors
Errors if self is a Scalar that fails to be converted into an array of size
Sourcepub fn create_null_array(num_rows: usize) -> Self
pub fn create_null_array(num_rows: usize) -> Self
Null columnar values are implemented as a null array in order to pass batch num_rows
Sourcepub fn values_to_arrays(args: &[ColumnarValue]) -> Result<Vec<ArrayRef>>
pub fn values_to_arrays(args: &[ColumnarValue]) -> Result<Vec<ArrayRef>>
Converts ColumnarValues to ArrayRefs with the same length.
§Performance Note
This function expands any ScalarValue to an array. This expansion
permits using a single function in terms of arrays, but it can be
inefficient compared to handling the scalar value directly.
Thus, it is recommended to provide specialized implementations for scalar values if performance is a concern.
§Errors
If there are multiple array arguments that have different lengths
Sourcepub fn cast_to(
&self,
cast_type: &DataType,
cast_options: Option<&CastOptions<'static>>,
) -> Result<ColumnarValue>
pub fn cast_to( &self, cast_type: &DataType, cast_options: Option<&CastOptions<'static>>, ) -> Result<ColumnarValue>
Cast’s this ColumnarValue to the specified DataType
Trait Implementations§
Source§impl Clone for ColumnarValue
impl Clone for ColumnarValue
Source§fn clone(&self) -> ColumnarValue
fn clone(&self) -> ColumnarValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ColumnarValue
impl Debug for ColumnarValue
Source§impl Display for ColumnarValue
impl Display for ColumnarValue
Source§impl From<ScalarValue> for ColumnarValue
impl From<ScalarValue> for ColumnarValue
Source§fn from(value: ScalarValue) -> Self
fn from(value: ScalarValue) -> Self
Auto Trait Implementations§
impl Freeze for ColumnarValue
impl !RefUnwindSafe for ColumnarValue
impl Send for ColumnarValue
impl Sync for ColumnarValue
impl Unpin for ColumnarValue
impl !UnwindSafe for ColumnarValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more