-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Use return_field_from_args in information schema and date_trunc #20079
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
Changes from all commits
4eb8af2
9d706cd
e8d78e8
3461f9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ use arrow::datatypes::{Field, FieldRef}; | |
| use datafusion_common::cast::as_primitive_array; | ||
| use datafusion_common::types::{NativeType, logical_date, logical_string}; | ||
| use datafusion_common::{ | ||
| DataFusionError, Result, ScalarValue, exec_datafusion_err, exec_err, | ||
| DataFusionError, Result, ScalarValue, exec_datafusion_err, exec_err, internal_err, | ||
| }; | ||
| use datafusion_expr::sort_properties::{ExprProperties, SortProperties}; | ||
| use datafusion_expr::{ | ||
|
|
@@ -223,27 +223,21 @@ impl ScalarUDFImpl for DateTruncFunc { | |
| &self.signature | ||
| } | ||
|
|
||
| // keep return_type implementation for information schema generation | ||
| fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update https://github.com/AndreaBozzo/datafusion/blob/e8d78e81765137be6fd7258e84cdcd62fdddd907/datafusion/functions/benches/date_trunc.rs#L61 to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks this should avoid internal_error, good catch |
||
| if arg_types[1].is_null() { | ||
| Ok(Timestamp(Nanosecond, None)) | ||
| } else { | ||
| Ok(arg_types[1].clone()) | ||
| } | ||
| fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> { | ||
| internal_err!("return_field_from_args should be called instead") | ||
| } | ||
|
|
||
| fn return_field_from_args(&self, args: ReturnFieldArgs) -> Result<FieldRef> { | ||
| let data_types = args | ||
| .arg_fields | ||
| .iter() | ||
| .map(|f| f.data_type()) | ||
| .cloned() | ||
| .collect::<Vec<_>>(); | ||
| let return_type = self.return_type(&data_types)?; | ||
| let field = &args.arg_fields[1]; | ||
| let return_type = if field.data_type().is_null() { | ||
| Timestamp(Nanosecond, None) | ||
| } else { | ||
| field.data_type().clone() | ||
| }; | ||
| Ok(Arc::new(Field::new( | ||
| self.name(), | ||
| return_type, | ||
| args.arg_fields[1].is_nullable(), | ||
| field.is_nullable(), | ||
| ))) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting that we omitted window functions before 🤔
And somehow this fix doesn't affect any existing tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good morning!
If i'm allowed, this could use a dedicated test/tests, at the same time i wanted to keep It lean for reviewers.
If any follow up Is needed, please consider me for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR is fine to merge as is, but I wouldn't be opposed to adding some SLT tests for that case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, i opened #20090 to track this as it might be a good newcomer task also
Thanks again for your review @Jefffrey