Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field trait method to WindowUDFImpl #12373

Closed
Tracked by #8709
jcsherin opened this issue Sep 7, 2024 · 0 comments · Fixed by #12374
Closed
Tracked by #8709

Add field trait method to WindowUDFImpl #12373

jcsherin opened this issue Sep 7, 2024 · 0 comments · Fixed by #12374
Labels
enhancement New feature or request

Comments

@jcsherin
Copy link
Contributor

jcsherin commented Sep 7, 2024

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>

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 */
       ))
    }
}

  1. Add the field trait method to WindowUDFImpl:
fn field(&self, field_args: WindowUDFFieldArgs) -> Result<Field>
  1. 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,
}
  1. Remove/Deprecate return_type trait method from WindowUDFImpl:

    /// What [`DataType`] will be returned by this function, given the types of
    /// the arguments
    fn return_type(&self, arg_types: &[DataType]) -> Result<DataType>;

  2. Remove nullable trait method from WindowUDFImpl:

    /// 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.

Additional context

Part of #8709.
Follow up to #12030.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant