jcsherin opened a new issue, #12373:
URL: https://github.com/apache/datafusion/issues/12373
### 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
have `field(&self, args: FieldArgs) -> Result<Field>`
```rust
FieldArgs {
arg_type: &[DataType]
schema: Schema // for nullable
}
```
> It is too late for AggregateUDF and ScalarUDF :(
_Originally posted by @jayzhan211 in
https://github.com/apache/datafusion/pull/12030#discussion_r1719736427_
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:
```rust
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:
```rust
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 */
))
}
}
```
---
1. Add the `field` trait method to `WindowUDFImpl`:
```rust
fn field(&self, field_args: WindowUDFFieldArgs) -> Result<Field>
```
2. Add `WindowUDFFieldArgs`:
```rust
/// 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,
}
```
3. Remove/Deprecate `return_type` trait method from `WindowUDFImpl`:
https://github.com/apache/datafusion/blob/502ce4bab6b09989a3412bd99795cba770f143b5/datafusion/expr/src/udwf.rs#L282-L284
4. Remove `nullable` trait method from `WindowUDFImpl`:
https://github.com/apache/datafusion/blob/502ce4bab6b09989a3412bd99795cba770f143b5/datafusion/expr/src/udwf.rs#L347-L354
### Describe alternatives you've considered
Make no changes to `WindowUDFImpl`.
### Additional context
_No response_
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]