datafusion_expr

Enum ColumnarValue

Source
pub enum ColumnarValue {
    Array(Arc<dyn Array>),
    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                 Scalar

Logically represents the following table:

Column 1Column 2
A100
B100
C100
D100
E100

§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§

§

Array(Arc<dyn Array>)

Array of values

§

Scalar(ScalarValue)

A single value

Implementations§

Source§

impl ColumnarValue

Source

pub fn data_type(&self) -> DataType

Source

pub fn into_array( self, num_rows: usize, ) -> Result<Arc<dyn Array>, DataFusionError>

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

Source

pub fn create_null_array(num_rows: usize) -> ColumnarValue

Null columnar values are implemented as a null array in order to pass batch num_rows

Source

pub fn values_to_arrays( args: &[ColumnarValue], ) -> Result<Vec<Arc<dyn Array>>, DataFusionError>

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

Source

pub fn cast_to( &self, cast_type: &DataType, cast_options: Option<&CastOptions<'static>>, ) -> Result<ColumnarValue, DataFusionError>

Cast’s this ColumnarValue to the specified DataType

Trait Implementations§

Source§

impl Clone for ColumnarValue

Source§

fn clone(&self) -> ColumnarValue

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ColumnarValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<Arc<dyn Array>> for ColumnarValue

Source§

fn from(value: Arc<dyn Array>) -> ColumnarValue

Converts to this type from the input type.
Source§

impl From<ScalarValue> for ColumnarValue

Source§

fn from(value: ScalarValue) -> ColumnarValue

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.