This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new cc6416e741 Minor: Add example for `ScalarUDF::call` (#11727)
cc6416e741 is described below
commit cc6416e7413e4a016f4a9070a801a7d5d9212745
Author: Andrew Lamb <[email protected]>
AuthorDate: Wed Jul 31 06:29:55 2024 -0400
Minor: Add example for `ScalarUDF::call` (#11727)
---
datafusion/expr/src/udf.rs | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs
index 487b098ea2..5ba6e3007e 100644
--- a/datafusion/expr/src/udf.rs
+++ b/datafusion/expr/src/udf.rs
@@ -46,6 +46,8 @@ use crate::{
/// 2. For advanced use cases, use [`ScalarUDFImpl`] which provides full API
/// access (examples in [`advanced_udf.rs`]).
///
+/// See [`Self::call`] to invoke a `ScalarUDF` with arguments.
+///
/// # API Note
///
/// This is a separate struct from `ScalarUDFImpl` to maintain backwards
@@ -121,7 +123,16 @@ impl ScalarUDF {
/// Returns a [`Expr`] logical expression to call this UDF with specified
/// arguments.
///
- /// This utility allows using the UDF without requiring access to the
registry.
+ /// This utility allows easily calling UDFs
+ ///
+ /// # Example
+ /// ```no_run
+ /// use datafusion_expr::{col, lit, ScalarUDF};
+ /// # fn my_udf() -> ScalarUDF { unimplemented!() }
+ /// let my_func: ScalarUDF = my_udf();
+ /// // Create an expr for `my_func(a, 12.3)`
+ /// let expr = my_func.call(vec![col("a"), lit(12.3)]);
+ /// ```
pub fn call(&self, args: Vec<Expr>) -> Expr {
Expr::ScalarFunction(crate::expr::ScalarFunction::new_udf(
Arc::new(self.clone()),
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]