-
Notifications
You must be signed in to change notification settings - Fork 847
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
feat: call try_merge recursively for list field #5852
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -483,6 +483,30 @@ impl Field { | |
)); | ||
} | ||
}, | ||
DataType::List(field) => match &from.data_type { | ||
DataType::List(from_field) => { | ||
let mut f = (**field).clone(); | ||
f.try_merge(from_field)?; | ||
(*field) = Arc::new(f); | ||
}, | ||
_ => { | ||
return Err(ArrowError::SchemaError( | ||
format!("Fail to merge schema field '{}' because the from data_type = {} is not DataType::List", | ||
self.name, from.data_type) | ||
))} | ||
}, | ||
DataType::LargeList(field) => match &from.data_type { | ||
DataType::LargeList(from_field) => { | ||
let mut f = (**field).clone(); | ||
f.try_merge(from_field)?; | ||
(*field) = Arc::new(f); | ||
}, | ||
_ => { | ||
return Err(ArrowError::SchemaError( | ||
format!("Fail to merge schema field '{}' because the from data_type = {} is not DataType::LargeList", | ||
self.name, from.data_type) | ||
))} | ||
}, | ||
DataType::Null => { | ||
self.nullable = true; | ||
self.data_type = from.data_type.clone(); | ||
|
@@ -509,9 +533,7 @@ impl Field { | |
| DataType::LargeBinary | ||
| DataType::BinaryView | ||
| DataType::Interval(_) | ||
| DataType::LargeList(_) | ||
| DataType::LargeListView(_) | ||
| DataType::List(_) | ||
| DataType::ListView(_) | ||
| DataType::Map(_, _) | ||
| DataType::Dictionary(_, _) | ||
|
@@ -623,6 +645,93 @@ mod test { | |
assert_eq!(Field::new("c2", DataType::Utf8, true), field2); | ||
} | ||
|
||
#[test] | ||
fn test_merge_with_nested_null() { | ||
let mut struct1 = Field::new( | ||
"s1", | ||
DataType::Struct(Fields::from(vec![Field::new( | ||
"inner", | ||
DataType::Float32, | ||
false, | ||
)])), | ||
false, | ||
); | ||
|
||
let struct2 = Field::new( | ||
"s2", | ||
DataType::Struct(Fields::from(vec![Field::new( | ||
"inner", | ||
DataType::Null, | ||
false, | ||
)])), | ||
true, | ||
); | ||
|
||
struct1 | ||
.try_merge(&struct2) | ||
.expect("should widen inner field's type to nullable float"); | ||
assert_eq!( | ||
Field::new( | ||
"s1", | ||
DataType::Struct(Fields::from(vec![Field::new( | ||
"inner", | ||
DataType::Float32, | ||
true, | ||
)])), | ||
true, | ||
), | ||
struct1 | ||
); | ||
|
||
let mut list1 = Field::new( | ||
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. Any chance we could add a test for |
||
"l1", | ||
DataType::List(Field::new("inner", DataType::Float32, false).into()), | ||
false, | ||
); | ||
|
||
let list2 = Field::new( | ||
"l2", | ||
DataType::List(Field::new("inner", DataType::Null, false).into()), | ||
true, | ||
); | ||
|
||
list1 | ||
.try_merge(&list2) | ||
.expect("should widen inner field's type to nullable float"); | ||
assert_eq!( | ||
Field::new( | ||
"l1", | ||
DataType::List(Field::new("inner", DataType::Float32, true).into()), | ||
true, | ||
), | ||
list1 | ||
); | ||
|
||
let mut large_list1 = Field::new( | ||
"ll1", | ||
DataType::LargeList(Field::new("inner", DataType::Float32, false).into()), | ||
false, | ||
); | ||
|
||
let large_list2 = Field::new( | ||
"ll2", | ||
DataType::LargeList(Field::new("inner", DataType::Null, false).into()), | ||
true, | ||
); | ||
|
||
large_list1 | ||
.try_merge(&large_list2) | ||
.expect("should widen inner field's type to nullable float"); | ||
assert_eq!( | ||
Field::new( | ||
"ll1", | ||
DataType::LargeList(Field::new("inner", DataType::Float32, true).into()), | ||
true, | ||
), | ||
large_list1 | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_fields_with_dict_id() { | ||
let dict1 = Field::new_dict( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we should also add support for
DataType::LargeList
https://docs.rs/arrow/latest/arrow/datatypes/enum.DataType.html#variant.LargeListIf you don't want to add it in this PR, I'll file a ticket to track and add it in a follow on