Enum datafusion::physical_plan::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> 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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V