Skip to content

Commit cc6416e

Browse files
authored
Minor: Add example for ScalarUDF::call (#11727)
1 parent 8ac50e2 commit cc6416e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

datafusion/expr/src/udf.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ use crate::{
4646
/// 2. For advanced use cases, use [`ScalarUDFImpl`] which provides full API
4747
/// access (examples in [`advanced_udf.rs`]).
4848
///
49+
/// See [`Self::call`] to invoke a `ScalarUDF` with arguments.
50+
///
4951
/// # API Note
5052
///
5153
/// This is a separate struct from `ScalarUDFImpl` to maintain backwards
@@ -121,7 +123,16 @@ impl ScalarUDF {
121123
/// Returns a [`Expr`] logical expression to call this UDF with specified
122124
/// arguments.
123125
///
124-
/// This utility allows using the UDF without requiring access to the registry.
126+
/// This utility allows easily calling UDFs
127+
///
128+
/// # Example
129+
/// ```no_run
130+
/// use datafusion_expr::{col, lit, ScalarUDF};
131+
/// # fn my_udf() -> ScalarUDF { unimplemented!() }
132+
/// let my_func: ScalarUDF = my_udf();
133+
/// // Create an expr for `my_func(a, 12.3)`
134+
/// let expr = my_func.call(vec![col("a"), lit(12.3)]);
135+
/// ```
125136
pub fn call(&self, args: Vec<Expr>) -> Expr {
126137
Expr::ScalarFunction(crate::expr::ScalarFunction::new_udf(
127138
Arc::new(self.clone()),

0 commit comments

Comments
 (0)