-
Notifications
You must be signed in to change notification settings - Fork 829
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: support cast between nested list and largelist #5121
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -788,7 +788,13 @@ pub fn cast_with_options( | |
cast_list_inner::<i64>(array, to, to_type, cast_options) | ||
} | ||
(List(list_from), LargeList(list_to)) => { | ||
if list_to.data_type() != list_from.data_type() { | ||
let to_type = list_to.data_type(); | ||
let from_type = list_from.data_type(); | ||
|
||
if to_type != from_type | ||
&& !(matches!(to_type, List(_) | LargeList(_)) | ||
|| matches!(from_type, List(_) | LargeList(_))) | ||
{ | ||
Err(ArrowError::CastError( | ||
"cannot cast list to large-list with different child data".into(), | ||
)) | ||
|
@@ -797,7 +803,13 @@ pub fn cast_with_options( | |
} | ||
} | ||
(LargeList(list_from), List(list_to)) => { | ||
if list_to.data_type() != list_from.data_type() { | ||
let to_type = list_to.data_type(); | ||
let from_type = list_from.data_type(); | ||
|
||
if to_type != from_type | ||
&& !(matches!(to_type, List(_) | LargeList(_)) | ||
|| matches!(from_type, List(_) | LargeList(_))) | ||
{ | ||
Err(ArrowError::CastError( | ||
"cannot cast large-list to list with different child data".into(), | ||
)) | ||
|
@@ -7459,6 +7471,48 @@ mod tests { | |
assert_eq!(&expected.value(2), &actual.value(2)); | ||
} | ||
|
||
#[test] | ||
fn test_cast_nested_list_container() { | ||
// large-list to list | ||
let array = Arc::new(make_large_list_array()) as ArrayRef; | ||
let list_array = cast( | ||
&array, | ||
&DataType::List(Arc::new(Field::new( | ||
"", | ||
DataType::List(Arc::new(Field::new("", DataType::Int32, false))), | ||
false, | ||
))), | ||
) | ||
.unwrap(); | ||
let actual = list_array.as_any().downcast_ref::<ListArray>().unwrap(); | ||
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. Can we please use AsArray in tests, i.e. |
||
let expected = array.as_any().downcast_ref::<LargeListArray>().unwrap(); | ||
|
||
assert_eq!(&expected.value(0), &actual.value(0)); | ||
assert_eq!(&expected.value(1), &actual.value(1)); | ||
assert_eq!(&expected.value(2), &actual.value(2)); | ||
|
||
// list to large-list | ||
let array = Arc::new(make_list_array()) as ArrayRef; | ||
let large_list_array = cast( | ||
&array, | ||
&DataType::LargeList(Arc::new(Field::new( | ||
"", | ||
DataType::LargeList(Arc::new(Field::new("", DataType::Int32, false))), | ||
false, | ||
))), | ||
) | ||
.unwrap(); | ||
let actual = large_list_array | ||
.as_any() | ||
.downcast_ref::<LargeListArray>() | ||
.unwrap(); | ||
let expected = array.as_any().downcast_ref::<ListArray>().unwrap(); | ||
|
||
assert_eq!(&expected.value(0), &actual.value(0)); | ||
assert_eq!(&expected.value(1), &actual.value(1)); | ||
assert_eq!(&expected.value(2), &actual.value(2)); | ||
} | ||
|
||
#[test] | ||
fn test_cast_list_to_fsl() { | ||
// There four noteworthy cases we should handle: | ||
|
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.
AFAICT this test simply ignores the nested list here, and is returning a non-nested list. This is consistent with my reading of cast_list_container