Struct datafusion_expr::ScalarUDF
source · 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(
name: &str,
signature: &Signature,
return_type: &ReturnTypeFunction,
fun: &ScalarFunctionImplementation,
) -> Self
👎Deprecated since 34.0.0: please implement ScalarUDFImpl instead
pub fn new( name: &str, signature: &Signature, return_type: &ReturnTypeFunction, fun: &ScalarFunctionImplementation, ) -> Self
Create a new ScalarUDF from low level details.
See ScalarUDFImpl
for a more convenient way to create a
ScalarUDF
using trait objects
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 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>
pub fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue>
Invoke the function on args
, returning the appropriate result.
See ScalarUDFImpl::invoke
for more details.
sourcepub fn invoke_no_args(&self, number_rows: usize) -> Result<ColumnarValue>
pub fn invoke_no_args(&self, number_rows: usize) -> Result<ColumnarValue>
Invoke 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
pub fn fun(&self) -> ScalarFunctionImplementation
Returns 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.
Trait Implementations§
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default 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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.