You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "jcsherin (via GitHub)" <gi...@apache.org> on 2024/09/07 13:35:31 UTC
[PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
jcsherin opened a new pull request, #12374:
URL: https://github.com/apache/datafusion/pull/12374
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #12373.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
The result field from evaluating the user-defined window function is composed from the `return_type` and `nullable` trait methods in `WindowUDFImpl`.
This change explores folding both methods into a single trait method. The user-defined window functions have to implement only the `field` trait method which makes the intent more explicit.
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 */
))
}
}
```
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
1. Add `field` trait method:
```rust
fn field(&self, field_args: WindowUDFFieldArgs) -> Result<Field>
```
2. Deprecate (or maybe remove) `return_type` trait method.
3. Remove `nullable` trait method which was added in #12030.
4. 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,
}
```
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
6. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
Yes, against existing tests in CI.
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
Yes, this is a breaking change for user-defined window functions API.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1748090967
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -204,7 +205,12 @@ impl ExprSchemable for Expr {
)
)
})?;
- Ok(fun.return_type(&new_types, &nullability)?)
+ let function_name = self.schema_name().to_string();
+ let field_args =
+ WindowUDFFieldArgs::new(&new_types, &function_name);
+
+ udwf.field(field_args)
+ .map(|field| field.data_type().clone())
Review Comment:
The data type of the Window UDF result is now derived from the `field` trait method. More verbose.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1748972478
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -352,7 +358,18 @@ impl ExprSchemable for Expr {
}
}
WindowFunctionDefinition::AggregateUDF(func) => Ok(func.is_nullable()),
- WindowFunctionDefinition::WindowUDF(udwf) => Ok(udwf.nullable()),
+ WindowFunctionDefinition::WindowUDF(udwf) => {
+ let data_types = args
+ .iter()
+ .map(|e| e.get_type(input_schema))
+ .collect::<Result<Vec<_>>>()?;
+ let input_types = data_types_with_window_udf(&data_types, udwf)?;
Review Comment:
Sounds good. I'll update the PR with the suggested change.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl`, remove `return_type`/`nullable` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1771928754
##########
datafusion/expr/src/udwf.rs:
##########
@@ -324,14 +317,8 @@ pub trait WindowUDFImpl: Debug + Send + Sync {
hasher.finish()
}
- /// 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
- }
+ /// The [`Field`] of the final result of evaluating this window function.
Review Comment:
Agreed. It's a great suggestion. I'll implement in a follow-up PR.
Thanks @Blizzara
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1763242140
##########
datafusion/expr/src/udwf.rs:
##########
@@ -159,13 +161,6 @@ impl WindowUDF {
self.inner.signature()
}
- /// Return the type of the function given its input types
- ///
- /// See [`WindowUDFImpl::return_type`] for more details.
- pub fn return_type(&self, args: &[DataType]) -> Result<DataType> {
- self.inner.return_type(args)
- }
-
Review Comment:
Removed `return_type`.
##########
datafusion/expr/src/udwf.rs:
##########
@@ -178,11 +173,11 @@ impl WindowUDF {
self.inner.partition_evaluator()
}
- /// Returns if column values are nullable for this window function.
+ /// Returns the field of the final result of evaluating this window function.
///
- /// See [`WindowUDFImpl::nullable`] for more details.
- pub fn nullable(&self) -> bool {
- self.inner.nullable()
Review Comment:
Removed `nullable`
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#issuecomment-2364187830
> If this is "too late" for this kind of comment, please let me know and I'll delete. I hadn't seen the issue / PR work until today.
@Michael-J-Ward Appreciate the extra set of eyes. Thank you, for reviewing the code :raised_hands:
> I dug into it because needing to add empty `&str` to all the tests in `datafusion/expr/src/expr.rs` made me think it's not the right abstraction.
https://github.com/apache/datafusion/blob/5cc7d06a0dd95dace219c666535630c1c7de3c3c/datafusion/expr/src/expr.rs#L704-L724
The `WindowFunctionDefintion::return_type` is used only for tests. And I believe these unit tests do not provide much value.
When `row_number()` was converted to `WindowUDF` the corresponding return type unit test for `row_number()` was removed. And I think this applies to the remaining builtin window methods which are pending conversion to `WindowUDF`.
@Michael-J-Ward @jayzhan211 Thank you.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl`, remove `return_type`/`nullable` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#issuecomment-2365152015
Thanks again @jayzhan211 and @jcsherin
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#issuecomment-2363043803
One performance consideration is that [Field::new](https://docs.rs/arrow/latest/arrow/datatypes/struct.Field.html#method.new) allocates a new string on each invocation.
> I don't think there is any issue given that we usually require the whole Field
Could that be why WindowUDF (and both ScalarUDF and AggregateUDF) preferred to keep the methods separate?
> Maybe historically issue?
> Lastly, do we want to diverge Aggregate and Window UDFs?
I don't think so, they should be separated, no any good reason to mix them
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1748091147
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -352,7 +358,18 @@ impl ExprSchemable for Expr {
}
}
WindowFunctionDefinition::AggregateUDF(func) => Ok(func.is_nullable()),
- WindowFunctionDefinition::WindowUDF(udwf) => Ok(udwf.nullable()),
+ WindowFunctionDefinition::WindowUDF(udwf) => {
+ let data_types = args
+ .iter()
+ .map(|e| e.get_type(input_schema))
+ .collect::<Result<Vec<_>>>()?;
+ let input_types = data_types_with_window_udf(&data_types, udwf)?;
+ let function_name = self.schema_name().to_string();
+ let field_args =
+ WindowUDFFieldArgs::new(&input_types, &function_name);
+
+ udwf.field(field_args).map(|field| field.is_nullable())
+ }
Review Comment:
Same here. The nullability of the Window UDF result is derived from the `field` trait method.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl`, remove `return_type`/`nullable` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#issuecomment-2379043093
> I also have it on my list to file some more sub task tickets for #8709 to remove the rest of the built in WindowFunctions
I filed a few more tickets to hopefully get this process started.
- [ ] https://github.com/apache/datafusion/issues/12648
- [ ] https://github.com/apache/datafusion/issues/12649
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#issuecomment-2335195809
I lack permission to apply the `api-change` label to this PR.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1763257580
##########
datafusion/expr/src/expr.rs:
##########
@@ -714,7 +716,9 @@ impl WindowFunctionDefinition {
WindowFunctionDefinition::AggregateUDF(fun) => {
fun.return_type(input_expr_types)
}
- WindowFunctionDefinition::WindowUDF(fun) => fun.return_type(input_expr_types),
+ WindowFunctionDefinition::WindowUDF(fun) => fun
+ .field(WindowUDFFieldArgs::new(input_expr_types, display_name))
+ .map(|field| field.data_type().clone()),
Review Comment:
Return data type for udwf.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl`, remove `return_type`/`nullable` [datafusion]
Posted by "Blizzara (via GitHub)" <gi...@apache.org>.
Blizzara commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1771016885
##########
datafusion/expr/src/udwf.rs:
##########
@@ -324,14 +317,8 @@ pub trait WindowUDFImpl: Debug + Send + Sync {
hasher.finish()
}
- /// 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
- }
+ /// The [`Field`] of the final result of evaluating this window function.
Review Comment:
Could be useful to document here how the "name" for the returned field is supposed to be set :)
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1763240579
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -499,6 +455,76 @@ impl ExprSchemable for Expr {
}
}
+impl Expr {
+ /// Common method for window functions that applies type coercion
+ /// to all arguments of the window function to check if it matches
+ /// its signature.
+ ///
+ /// If successful, this method returns the data type and
+ /// nullability of the window function's result.
+ ///
+ /// Otherwise, returns an error if there's a type mismatch between
+ /// the window function's signature and the provided arguments.
+ fn data_type_and_nullable_with_window_function(
+ &self,
+ schema: &dyn ExprSchema,
+ window_function: &WindowFunction,
+ ) -> Result<(DataType, bool)> {
Review Comment:
Extracted a common method to handle type coercion for all window function types (built-in, udaf and udwf) which is then reused by methods:,
- `data_type_and_nullable`,
- `get_type` and,
- `nullable`
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl`, remove `return_type`/`nullable` [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #12374:
URL: https://github.com/apache/datafusion/pull/12374
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1748094446
##########
datafusion/expr/src/expr.rs:
##########
@@ -714,7 +714,12 @@ impl WindowFunctionDefinition {
WindowFunctionDefinition::AggregateUDF(fun) => {
fun.return_type(input_expr_types)
}
- WindowFunctionDefinition::WindowUDF(fun) => fun.return_type(input_expr_types),
+ WindowFunctionDefinition::WindowUDF(_) => {
+ // To get the return data type of the result from
+ // evaluating the user-defined window function instead
+ // use the `WindowUDF::field` trait method.
+ unreachable!()
+ }
Review Comment:
Side-effect of deriving the return type from `field` trait method.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1763245501
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -499,6 +455,76 @@ impl ExprSchemable for Expr {
}
}
+impl Expr {
+ /// Common method for window functions that applies type coercion
+ /// to all arguments of the window function to check if it matches
+ /// its signature.
+ ///
+ /// If successful, this method returns the data type and
+ /// nullability of the window function's result.
+ ///
+ /// Otherwise, returns an error if there's a type mismatch between
+ /// the window function's signature and the provided arguments.
+ fn data_type_and_nullable_with_window_function(
+ &self,
+ schema: &dyn ExprSchema,
+ window_function: &WindowFunction,
+ ) -> Result<(DataType, bool)> {
+ let WindowFunction { fun, args, .. } = window_function;
+
+ let data_types = args
+ .iter()
+ .map(|e| e.get_type(schema))
+ .collect::<Result<Vec<_>>>()?;
+ match fun {
+ WindowFunctionDefinition::BuiltInWindowFunction(window_fun) => {
+ let return_type = window_fun.return_type(&data_types)?;
+ let nullable =
+ !["RANK", "NTILE", "CUME_DIST"].contains(&window_fun.name());
+ Ok((return_type, nullable))
+ }
+ WindowFunctionDefinition::AggregateUDF(udaf) => {
+ let new_types = data_types_with_aggregate_udf(&data_types, udaf)
+ .map_err(|err| {
+ plan_datafusion_err!(
+ "{} {}",
+ err,
+ utils::generate_signature_error_msg(
+ fun.name(),
+ fun.signature(),
+ &data_types
+ )
+ )
+ })?;
+
+ let return_type = udaf.return_type(&new_types)?;
+ let nullable = udaf.is_nullable();
+
+ Ok((return_type, nullable))
+ }
+ WindowFunctionDefinition::WindowUDF(udwf) => {
+ let new_types =
+ data_types_with_window_udf(&data_types, udwf).map_err(|err| {
+ plan_datafusion_err!(
+ "{} {}",
+ err,
+ utils::generate_signature_error_msg(
+ fun.name(),
+ fun.signature(),
+ &data_types
+ )
+ )
+ })?;
+ let (_, function_name) = self.qualified_name();
Review Comment:
Use `Expr::qualified_name` which also handles:
- `Expr::Column` and,
- `Expr::Alias`
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#issuecomment-2360542676
Thanks @jayzhan211
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1748093573
##########
datafusion/expr/src/udwf.rs:
##########
@@ -419,6 +421,7 @@ impl WindowUDFImpl for AliasedWindowUDFImpl {
self.inner.signature()
}
+ #[allow(deprecated)]
Review Comment:
Satisfies clippy.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1748093341
##########
datafusion/expr/src/udwf.rs:
##########
@@ -281,6 +285,10 @@ pub trait WindowUDFImpl: Debug + Send + Sync {
/// What [`DataType`] will be returned by this function, given the types of
/// the arguments
+ #[deprecated(
+ since = "41.0.0",
+ note = "Use `field` instead to define the final result of evaluating this user-defined window function."
+ )]
Review Comment:
Maybe remove this right now instead of marking it as deprecated?
I checked and the deprecated warning does not show for trait implementations. It is only shown as a warning during cargo build and an error in clippy when the trait method is called.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1748094081
##########
datafusion/physical-plan/src/windows/mod.rs:
##########
@@ -73,7 +74,15 @@ pub fn schema_add_window_field(
.iter()
.map(|e| Arc::clone(e).as_ref().nullable(schema))
.collect::<Result<Vec<_>>>()?;
- let window_expr_return_type = window_fn.return_type(&data_types, &nullability)?;
+ let window_expr_return_type =
+ if let WindowFunctionDefinition::WindowUDF(udwf) = window_fn {
+ let field_args = WindowUDFFieldArgs::new(&data_types, fn_name);
+
+ udwf.field(field_args)
+ .map(|field| field.data_type().clone())?
+ } else {
+ window_fn.return_type(&data_types, &nullability)?
+ };
Review Comment:
Window UDF derives data type through `field`.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1748092364
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -352,7 +358,18 @@ impl ExprSchemable for Expr {
}
}
WindowFunctionDefinition::AggregateUDF(func) => Ok(func.is_nullable()),
- WindowFunctionDefinition::WindowUDF(udwf) => Ok(udwf.nullable()),
+ WindowFunctionDefinition::WindowUDF(udwf) => {
+ let data_types = args
+ .iter()
+ .map(|e| e.get_type(input_schema))
+ .collect::<Result<Vec<_>>>()?;
+ let input_types = data_types_with_window_udf(&data_types, udwf)?;
Review Comment:
Note: I copied the call to `data_types_with_window_udf`: type-coercion performed for window function arguments from `Expr::get_type` (above).
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jcsherin (via GitHub)" <gi...@apache.org>.
jcsherin commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1748092364
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -352,7 +358,18 @@ impl ExprSchemable for Expr {
}
}
WindowFunctionDefinition::AggregateUDF(func) => Ok(func.is_nullable()),
- WindowFunctionDefinition::WindowUDF(udwf) => Ok(udwf.nullable()),
+ WindowFunctionDefinition::WindowUDF(udwf) => {
+ let data_types = args
+ .iter()
+ .map(|e| e.get_type(input_schema))
+ .collect::<Result<Vec<_>>>()?;
+ let input_types = data_types_with_window_udf(&data_types, udwf)?;
Review Comment:
Note: I copied the call to type-coercion performed for window function arguments from `Expr::get_type` (above).
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add `field` trait method to `WindowUDFImpl` [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #12374:
URL: https://github.com/apache/datafusion/pull/12374#discussion_r1748097339
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -352,7 +358,18 @@ impl ExprSchemable for Expr {
}
}
WindowFunctionDefinition::AggregateUDF(func) => Ok(func.is_nullable()),
- WindowFunctionDefinition::WindowUDF(udwf) => Ok(udwf.nullable()),
+ WindowFunctionDefinition::WindowUDF(udwf) => {
+ let data_types = args
+ .iter()
+ .map(|e| e.get_type(input_schema))
+ .collect::<Result<Vec<_>>>()?;
+ let input_types = data_types_with_window_udf(&data_types, udwf)?;
+ let function_name = self.schema_name().to_string();
Review Comment:
Similar to `self.qualified_name()` in `to_field`, we might have different name for Column and Alias?
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -352,7 +358,18 @@ impl ExprSchemable for Expr {
}
}
WindowFunctionDefinition::AggregateUDF(func) => Ok(func.is_nullable()),
- WindowFunctionDefinition::WindowUDF(udwf) => Ok(udwf.nullable()),
+ WindowFunctionDefinition::WindowUDF(udwf) => {
+ let data_types = args
+ .iter()
+ .map(|e| e.get_type(input_schema))
+ .collect::<Result<Vec<_>>>()?;
+ let input_types = data_types_with_window_udf(&data_types, udwf)?;
Review Comment:
I think we should handle this compute in `to_field`. `data_types_with_window_udf` could reuse `to_field`. `data_types` and `nullable` could reuse `data_types_with_window_udf`
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org