alamb commented on code in PR #8985:
URL: https://github.com/apache/arrow-datafusion/pull/8985#discussion_r1490927941
##########
datafusion/expr/src/udf.rs:
##########
@@ -249,6 +257,43 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
/// the arguments
fn return_type(&self, arg_types: &[DataType]) -> Result<DataType>;
+ /// What [`DataType`] will be returned by this function, given the
+ /// arguments?
+ ///
+ /// Note most UDFs should implement [`Self::return_type`] and not this
+ /// function. The output type for most functions only depends on the types
+ /// of their inputs (e.g. `sqrt(f32)` is always `f32`).
+ ///
+ /// By default, this function calls [`Self::return_type`] with the
+ /// types of each argument.
+ ///
+ /// This method can be overridden for functions that return different
+ /// *types* based on the *values* of their arguments.
+ ///
+ /// For example, the following two function calls get the same argument
+ /// types (something and a `Utf8` string) but return different types based
+ /// on the value of the second argument:
+ ///
+ /// * `arrow_cast(x, 'Int16')` --> `Int16`
+ /// * `arrow_cast(x, 'Float32')` --> `Float32`
+ ///
+ /// # Notes:
+ ///
+ /// This function must consistently return the same type for the same
+ /// logical input even if the input is simplified (e.g. it must return the
same
+ /// value for `('foo' | 'bar')` as it does for ('foobar').
Review Comment:
Excellent idea - added in 653577f9a
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]