Struct datafusion_physical_expr::udf::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 (less performant) use cases, use
create_udf
andsimple_udf.rs
. -
For advanced use cases, use
ScalarUDFImpl
andadvanced_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: &Arc<dyn Fn(&[DataType]) -> Result<Arc<DataType>, DataFusionError> + Send + Sync>,
fun: &Arc<dyn Fn(&[ColumnarValue]) -> Result<ColumnarValue, DataFusionError> + Send + Sync>
) -> ScalarUDF
👎Deprecated since 34.0.0: please implement ScalarUDFImpl instead
pub fn new( name: &str, signature: &Signature, return_type: &Arc<dyn Fn(&[DataType]) -> Result<Arc<DataType>, DataFusionError> + Send + Sync>, fun: &Arc<dyn Fn(&[ColumnarValue]) -> Result<ColumnarValue, DataFusionError> + Send + Sync> ) -> ScalarUDF
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>
) -> ScalarUDF
pub fn with_aliases( self, aliases: impl IntoIterator<Item = &'static str> ) -> ScalarUDF
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(
&self,
args: &[DataType]
) -> Result<DataType, DataFusionError>
pub fn return_type( &self, args: &[DataType] ) -> Result<DataType, DataFusionError>
The datatype this function returns given the input argument input types.
See ScalarUDFImpl::return_type
for more details.
sourcepub fn invoke(
&self,
args: &[ColumnarValue]
) -> Result<ColumnarValue, DataFusionError>
pub fn invoke( &self, args: &[ColumnarValue] ) -> Result<ColumnarValue, DataFusionError>
Invoke the function on args
, returning the appropriate result.
See ScalarUDFImpl::invoke
for more details.
sourcepub fn fun(
&self
) -> Arc<dyn Fn(&[ColumnarValue]) -> Result<ColumnarValue, DataFusionError> + Send + Sync>
pub fn fun( &self ) -> Arc<dyn Fn(&[ColumnarValue]) -> Result<ColumnarValue, DataFusionError> + Send + Sync>
Returns a ScalarFunctionImplementation
that can invoke the function
during execution
sourcepub fn monotonicity(&self) -> Result<Option<Vec<Option<bool>>>, DataFusionError>
pub fn monotonicity(&self) -> Result<Option<Vec<Option<bool>>>, DataFusionError>
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 !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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.