Description
Is your feature request related to a problem or challenge?
Instead of return_type + nullable. I think
field
is 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
field
trait 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_type
trait method fromWindowUDFImpl
:
datafusion/datafusion/expr/src/udwf.rs
Lines 282 to 284 in 502ce4b
-
Remove
nullable
trait method fromWindowUDFImpl
:
datafusion/datafusion/expr/src/udwf.rs
Lines 347 to 354 in 502ce4b
Describe alternatives you've considered
Make no changes to WindowUDFImpl
.