-
Couldn't load subscription status.
- Fork 1.7k
Description
Is your feature request related to a problem or challenge?
Instead of return_type + nullable. I think
fieldis a better choice. Given windowudf is pretty new so not widely used yet (?). It would be nice to havefield(&self, args: FieldArgs) -> Result<Field>
FieldArgs {
arg_type: &[DataType]
schema: Schema // for nullable
}It is too late for AggregateUDF and ScalarUDF :(
Originally posted by @jayzhan211 in #12030 (comment)
This is a proposal to add a field trait method for implementing user-defined window functions. And also remove (or deprecate) the trait methods return_type and nullable from WindowUDFImpl.
Both the return data type and nullability of the result from evaluating the user-defined window function will be specified by the field implementation.
Describe the solution you'd like
The current implementation for a user-defined window function (without field trait method) looks like this:
impl WindowUDFImpl for RowNumber {
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
Ok(DataType::UInt64)
}
fn nullable(&self) -> bool {
true
}
}The implementation for a user-defined window function after this change:
impl WindowUDFImpl for RowNumber {
fn field(&self, field_args: WindowUDFFieldArgs) -> Result<Field> {
Ok(Field::new(
field_args.name(), /* window function display name */
DataType::UInt64, /* result data type */
false /* row number is not nullable */
))
}
}- Add the
fieldtrait method toWindowUDFImpl:
fn field(&self, field_args: WindowUDFFieldArgs) -> Result<Field>- Add
WindowUDFFieldArgs:
/// Contains metadata necessary for defining the field which represents
/// the final result of evaluating a user-defined window function.
pub struct WindowUDFFieldArgs<'a> {
/// The data types of input expressions to the user-defined window
/// function.
input_types: &'a [DataType],
/// The display name of the user-defined window function.
function_name: &'a str,
}-
Remove/Deprecate
return_typetrait method fromWindowUDFImpl:
datafusion/datafusion/expr/src/udwf.rs
Lines 282 to 284 in 502ce4b
/// What [`DataType`] will be returned by this function, given the types of /// the arguments fn return_type(&self, arg_types: &[DataType]) -> Result<DataType>; -
Remove
nullabletrait method fromWindowUDFImpl:
datafusion/datafusion/expr/src/udwf.rs
Lines 347 to 354 in 502ce4b
/// Allows customizing nullable of column for this window UDF. /// /// By default, the final result of evaluating the window UDF is /// allowed to have null values. But if that is not the case then /// it can be customized in the window UDF implementation. fn nullable(&self) -> bool { true }
Describe alternatives you've considered
Make no changes to WindowUDFImpl.