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
ScalarUDFImplwhich provides full API access (examples inadvanced_udf.rs).
§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 call(&self, args: Vec<Expr>) -> Expr
pub fn call(&self, args: Vec<Expr>) -> Expr
Returns a Expr logical expression to call this UDF with specified
arguments.
This utility allows using the UDF without requiring access to the registry.
sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns this function’s name.
See ScalarUDFImpl::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 Exprs.
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 fun(&self) -> ScalarFunctionImplementation
pub fn fun(&self) -> ScalarFunctionImplementation
Returns a ScalarFunctionImplementation that can invoke the function
during execution
sourcepub fn monotonicity(&self) -> Result<Option<FuncMonotonicity>>
pub fn monotonicity(&self) -> Result<Option<FuncMonotonicity>>
This function specifies monotonicity behaviors for User defined scalar functions.
See ScalarUDFImpl::monotonicity for more details.
Trait Implementations§
source§impl PartialEq for ScalarUDF
impl PartialEq 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<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.