pub struct ScalarUDF { /* private fields */ }
Expand description
Logical representation of a Scalar User Defined Function.
A scalar function produces a single row output for each row of input. This struct contains the information DataFusion needs to plan and invoke functions you supply such name, type signature, return type, and actual implementation.
-
For simple use cases, use
create_udf
(examples insimple_udf.rs
). -
For advanced use cases, use
ScalarUDFImpl
which provides full API access (examples inadvanced_udf.rs
).
See Self::call
to invoke a ScalarUDF
with arguments.
§API Note
This is a separate struct from ScalarUDFImpl
to maintain backwards
compatibility with the older API.
Implementations§
Source§impl ScalarUDF
impl ScalarUDF
Sourcepub fn new_from_impl<F>(fun: F) -> ScalarUDFwhere
F: ScalarUDFImpl + 'static,
pub fn new_from_impl<F>(fun: F) -> ScalarUDFwhere
F: ScalarUDFImpl + 'static,
Create a new ScalarUDF
from a [ScalarUDFImpl]
trait object
Note this is the same as using the From
impl (ScalarUDF::from
)
Sourcepub fn inner(&self) -> &Arc<dyn ScalarUDFImpl>
pub fn inner(&self) -> &Arc<dyn ScalarUDFImpl>
Return the underlying ScalarUDFImpl
trait object for this function
Sourcepub fn with_aliases(
self,
aliases: impl IntoIterator<Item = &'static str>,
) -> Self
pub fn with_aliases( self, aliases: impl IntoIterator<Item = &'static str>, ) -> Self
Adds additional names that can be used to invoke this function, in
addition to name
If you implement ScalarUDFImpl
directly you should return aliases directly.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns this function’s name.
See ScalarUDFImpl::name
for more details.
Sourcepub fn display_name(&self, args: &[Expr]) -> Result<String>
pub fn display_name(&self, args: &[Expr]) -> Result<String>
Returns this function’s display_name.
See ScalarUDFImpl::display_name
for more details
Sourcepub fn schema_name(&self, args: &[Expr]) -> Result<String>
pub fn schema_name(&self, args: &[Expr]) -> Result<String>
Returns this function’s schema_name.
See ScalarUDFImpl::schema_name
for more details
Sourcepub fn aliases(&self) -> &[String]
pub fn aliases(&self) -> &[String]
Returns the aliases for this function.
See ScalarUDF::with_aliases
for more details
Sourcepub fn signature(&self) -> &Signature
pub fn signature(&self) -> &Signature
Returns this function’s Signature
(what input types are accepted).
See ScalarUDFImpl::signature
for more details.
Sourcepub fn return_type_from_exprs(
&self,
args: &[Expr],
schema: &dyn ExprSchema,
arg_types: &[DataType],
) -> Result<DataType>
pub fn return_type_from_exprs( &self, args: &[Expr], schema: &dyn ExprSchema, arg_types: &[DataType], ) -> Result<DataType>
The datatype this function returns given the input argument input types.
This function is used when the input arguments are Expr
s.
See ScalarUDFImpl::return_type_from_exprs
for more details.
Sourcepub fn simplify(
&self,
args: Vec<Expr>,
info: &dyn SimplifyInfo,
) -> Result<ExprSimplifyResult>
pub fn simplify( &self, args: Vec<Expr>, info: &dyn SimplifyInfo, ) -> Result<ExprSimplifyResult>
Do the function rewrite
See ScalarUDFImpl::simplify
for more details.
Sourcepub fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue>
👎Deprecated since 42.1.0: Use invoke_batch
instead
pub fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue>
invoke_batch
insteadInvoke the function on args
, returning the appropriate result.
See ScalarUDFImpl::invoke
for more details.
pub fn is_nullable(&self, args: &[Expr], schema: &dyn ExprSchema) -> bool
Sourcepub fn invoke_batch(
&self,
args: &[ColumnarValue],
number_rows: usize,
) -> Result<ColumnarValue>
pub fn invoke_batch( &self, args: &[ColumnarValue], number_rows: usize, ) -> Result<ColumnarValue>
Invoke the function with args
and number of rows, returning the appropriate result.
See ScalarUDFImpl::invoke_batch
for more details.
Sourcepub fn invoke_no_args(&self, number_rows: usize) -> Result<ColumnarValue>
👎Deprecated since 42.1.0: Use invoke_batch
instead
pub fn invoke_no_args(&self, number_rows: usize) -> Result<ColumnarValue>
invoke_batch
insteadInvoke the function without args
but number of rows, returning the appropriate result.
See ScalarUDFImpl::invoke_no_args
for more details.
Sourcepub fn fun(&self) -> ScalarFunctionImplementation
👎Deprecated since 42.0.0: Use invoke_batch
instead
pub fn fun(&self) -> ScalarFunctionImplementation
invoke_batch
insteadReturns a ScalarFunctionImplementation
that can invoke the function
during execution
Sourcepub fn short_circuits(&self) -> bool
pub fn short_circuits(&self) -> bool
Get the circuits of inner implementation
Sourcepub fn evaluate_bounds(&self, inputs: &[&Interval]) -> Result<Interval>
pub fn evaluate_bounds(&self, inputs: &[&Interval]) -> Result<Interval>
Sourcepub fn propagate_constraints(
&self,
interval: &Interval,
inputs: &[&Interval],
) -> Result<Option<Vec<Interval>>>
pub fn propagate_constraints( &self, interval: &Interval, inputs: &[&Interval], ) -> Result<Option<Vec<Interval>>>
Updates bounds for child expressions, given a known interval for this function. This is used to propagate constraints down through an expression tree.
§Parameters
interval
is the currently known interval for this function.inputs
are the current intervals for the inputs (children) of this function.
§Returns
A Vec
of new intervals for the children, in order.
If constraint propagation reveals an infeasibility for any child, returns
None
. If none of the children intervals change as a result of
propagation, may return an empty vector instead of cloning children
.
This is the default (and conservative) return value.
§Example
If the function is ABS(a)
, the current interval
is [4, 5]
and the
input a
is given as [-7, 3]
, then propagation would return [-5, 3]
.
Sourcepub fn output_ordering(
&self,
inputs: &[ExprProperties],
) -> Result<SortProperties>
pub fn output_ordering( &self, inputs: &[ExprProperties], ) -> Result<SortProperties>
Calculates the SortProperties
of this function based on its
children’s properties.
Sourcepub fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>>
pub fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>>
See ScalarUDFImpl::coerce_types
for more details.
Sourcepub fn documentation(&self) -> Option<&Documentation>
pub fn documentation(&self) -> Option<&Documentation>
Returns the documentation for this Scalar UDF.
Documentation can be accessed programmatically as well as generating publicly facing documentation.
Trait Implementations§
Source§impl PartialOrd for ScalarUDF
impl PartialOrd for ScalarUDF
impl Eq for ScalarUDF
Auto Trait Implementations§
impl Freeze for ScalarUDF
impl !RefUnwindSafe for ScalarUDF
impl Send for ScalarUDF
impl Sync for ScalarUDF
impl Unpin for ScalarUDF
impl !UnwindSafe for ScalarUDF
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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