-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: spark array return type mismatch when inner data type is LargeList #18485
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
Conversation
| 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)?; | ||
| Ok(Arc::new(Field::new( | ||
| "this_field_name_is_irrelevant", | ||
| return_type, | ||
| false, | ||
| ))) | ||
| } |
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'm actually thinking maybe we keep this and just fold return_type logic into here; specifically because it returns false for the nullability whereas default implementation for return_field_from_args returns true for nullability.
- We'd still need to implement
return_typeto satisfy trait, but we can have it return an internal err, see:
datafusion/datafusion/functions-nested/src/map_values.rs
Lines 95 to 112 in b52a81d
| fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> { | |
| internal_err!("return_field_from_args should be used instead") | |
| } | |
| fn return_field_from_args( | |
| &self, | |
| args: datafusion_expr::ReturnFieldArgs, | |
| ) -> Result<FieldRef> { | |
| let [map_type] = take_function_args(self.name(), args.arg_fields)?; | |
| Ok(Field::new( | |
| self.name(), | |
| DataType::List(get_map_values_field_as_list_field(map_type.data_type())?), | |
| // Nullable if the map is nullable | |
| args.arg_fields.iter().any(|x| x.is_nullable()), | |
| ) | |
| .into()) | |
| } |
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.
Ah thanks for pointing it out, will raise a revision.
For my learning, make_array implements return_type but not return_field_from_args,
| fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> { |
return_field_from_args that has nullable set to true. How would nullability on the return field affect behavior of sql queries? Thanks.
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'm not familiar with the degree to which DataFusion uses the nullability information of a field, so I can't say what the impact would be. But I assume it's better to be more informative where possible, e.g. we know make array function can't ever return a null so it's good if we can preserve that information, especially since the Spark version already had it.
…8373) ## Which issue does this PR close? - None, This is a follow-up for apache#18298 ## Rationale for this change This moves the projection logic from `generate_series` out of the generator into `LazyMemoryStream` as discussed in apache#18298 (comment) This makes the projection logic generic for all generators. ## What changes are included in this PR? The projection logic is moved from `generate_series` into the `LazyMemoryStream` and relevant tests, where `LazyMemoryStream` is used, are adapted accordingly. ## Are these changes tested? This is only a small refactoring; the changes are covered by the tests from apache#18298 ## Are there any user-facing changes? There is a new parameter added to LazyMemoryExec::try_new method
## 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 apache#123` indicates that this PR will close issue apache#123. --> - part of #apache#18142. ## Rationale for this change As discussed in apache#18289 this PR is for consolidating all the `flight` examples into a single example binary. Then we can make sure we are agreed on the pattern and then we can apply it to the remaining examples <!-- 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. --> ## 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. --> ## 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 2. 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)? --> ## 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. --> --------- Co-authored-by: Sergey Zhukov <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
…8389) ## Which issue does this PR close? Addresses portions of apache#17379. ## Rationale for this change Add support for aggregate and window UDFs in the same way as we did it for scalar UDFs here: apache#18019 ## Are these changes tested? Yes ## Are there any user-facing changes? Yes, the changes are user-facing, documented, purely additive and non-breaking.
## Which issue does this PR close? - Closes apache#18350. ## Rationale for this change We want to be able to reverse a ListView. ## What changes are included in this PR? - Downcast `&dyn Array` to `ListView`: `as_list_view_array` - Downcast `&dyn Array` to `LargeListView`: `as_large_list_view_array` - Branches in `array_reverse_inner` to reverse `ListView` and `LargeListView` - Main logic in `list_view_reverse` which materializes a new values array using `take` ## Are these changes tested? Yes
|
Thanks @jizezhang |
Which issue does this PR close?
Rationale for this change
This PR is intended to fix return type mismatch of spark
arraywhen inner data type isLargeList, e.g.What changes are included in this PR?
Listregardless of whether inner data type isLargeListor not. This aligns with the behavior of datafusionmake_arrayfunction.return_field_from_argsasreturn_typeis already defined and is invoked internally.Are these changes tested?
Yes
Are there any user-facing changes?
No.