@@ -317,9 +317,9 @@ pub struct ScalarFunctionArgs<'a, 'b> {
317
317
pub struct ReturnFieldArgs < ' a > {
318
318
/// The data types of the arguments to the function
319
319
pub arg_fields : & ' a [ Field ] ,
320
- /// Is argument `i` to the function a scalar (constant)
320
+ /// Is argument `i` to the function a scalar (constant)?
321
321
///
322
- /// If argument `i` is not a scalar, it will be None
322
+ /// If the argument `i` is not a scalar, it will be None
323
323
///
324
324
/// For example, if a function is called like `my_function(column_a, 5)`
325
325
/// this field will be `[None, Some(ScalarValue::Int32(Some(5)))]`
@@ -451,16 +451,37 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
451
451
///
452
452
/// # Notes
453
453
///
454
- /// Most UDFs should implement [`Self::return_type`] and not this
455
- /// function as the output type for most functions only depends on the types
456
- /// of their inputs (e.g. `sqrt(f32)` is always `f32`).
454
+ /// For the majority of UDFs, implementing [`Self::return_type`] is sufficient,
455
+ /// as the result type is typically a deterministic function of the input types
456
+ /// (e.g., `sqrt(f32)` consistently yields `f32`). Implementing this method directly
457
+ /// is generally unnecessary unless the return type depends on runtime values.
457
458
///
458
459
/// This function can be used for more advanced cases such as:
459
460
///
460
461
/// 1. specifying nullability
461
462
/// 2. return types based on the **values** of the arguments (rather than
462
463
/// their **types**.
463
464
///
465
+ /// # Example creating `Field`
466
+ ///
467
+ /// Note the [`Field`] is ignored, except for structured types such as
468
+ /// `DataType::Struct`.
469
+ ///
470
+ /// ```rust
471
+ /// # use arrow::datatypes::{DataType, Field};
472
+ /// # use datafusion_common::Result;
473
+ /// # use datafusion_expr::ReturnFieldArgs;
474
+ /// # struct Example{};
475
+ /// # impl Example {
476
+ /// fn return_field_from_args(&self, args: ReturnFieldArgs) -> Result<Field> {
477
+ /// // report output is only nullable if any one of the arguments are nullable
478
+ /// let nullable = args.arg_fields.iter().any(|f| f.is_nullable());
479
+ /// let field = Field::new("ignored_name", DataType::Int32, true);
480
+ /// Ok(field)
481
+ /// }
482
+ /// # }
483
+ /// ```
484
+ ///
464
485
/// # Output Type based on Values
465
486
///
466
487
/// For example, the following two function calls get the same argument
0 commit comments