Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions datafusion/expr/src/columnar_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ use datafusion_common::{internal_err, Result, ScalarValue};
use std::sync::Arc;

/// Represents the result of evaluating an expression: either a single
/// `ScalarValue` or an [`ArrayRef`].
/// [`ScalarValue`] or an [`ArrayRef`].
///
/// While a [`ColumnarValue`] can always be converted into an array
/// for convenience, it is often much more performant to provide an
/// optimized path for scalar values.
///
/// See [`ColumnarValue::values_to_arrays`] for a function that converts
/// multiple columnar values into arrays of the same length.
#[derive(Clone, Debug)]
pub enum ColumnarValue {
/// Array of values
Expand Down Expand Up @@ -59,8 +62,13 @@ impl ColumnarValue {
}
}

/// Convert a columnar value into an ArrayRef. [`Self::Scalar`] is
/// converted by repeating the same scalar multiple times.
/// 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
///
Expand Down
6 changes: 4 additions & 2 deletions datafusion/expr/src/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,10 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
///
/// For the best performance, the implementations of `invoke` should handle
/// the common case when one or more of their arguments are constant values
/// (aka [`ColumnarValue::Scalar`]). Calling [`ColumnarValue::into_array`]
/// and treating all arguments as arrays will work, but will be slower.
/// (aka [`ColumnarValue::Scalar`]).
///
/// [`ColumnarValue::values_to_arrays`] can be used to convert the arguments
/// to arrays, which will likely be simpler code, but be slower.
fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue>;

/// Returns any aliases (alternate names) for this function.
Expand Down